如何实现ios屏幕的横竖屏自适应


首先在UIViewController的
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
方法中设置设备要支持的deviceOrientation;
在UIViewController的
-(void)willRotateToInterfaceOrientation(UIInterfaceOrientation)toInterfaceOrientation 
duration:(NSTimeInterval)duration
或者
-(void)willAnimateRotationToInterfaceOrientation(UIInterfaceOrientation)interfaceOrientation
duration:(NSTimeInterval)duration
重新设置所有子view的frame
 
当UIView设置成自动适配屏幕(即myView.autoresizesSubviews = YES)时,当我们重新设置myView的frame时(一般屏幕旋转时我们都会重新设置view的frame),会自动调用layoutSubviers方法,我们可以在该方法中判断屏幕的方向,并调整各子view的frame。
 
如果工层中有一个superViewController,然后在该控制器的试图上加上了另一个subViewController的view,无论如何subViewController的以上三个方法都不会被调用,这个时候,可以在superViewController的
-(void)willRotateToInterfaceOrientation(UIInterfaceOrientation)toInterfaceOrientation 
duration:(NSTimeInterval)duration
或者
-(void)willAnimateRotationToInterfaceOrientation(UIInterfaceOrientation)interfaceOrientation
duration:(NSTimeInterval)duration
方法中重新配置subViewController的view。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM