您的位置:首页 > 移动开发 > IOS开发

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

2012-12-10 10:54 399 查看

如何实现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。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: