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

IOS 4,5和6上对设备方向支持方法的变更

2013-10-13 11:40 531 查看
在IOS4,5上,设备的支持方向是每个view controller定义,默认是只能portrait,修改的话调用shouldAutorotateToInterfaceOrientation:方法,如:

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight;

}


在IOS 6以后,设备的支持方向,只能在rootviewcontroller(或Presentmodelviewcontroller上)设定支持方向,subview或者 child Viewcontroller根据rootviewcontroller来,
在rootviewcontroller里面调用:

// New Autorotation support.
- (BOOL)shouldAutorotate NS_AVAILABLE_IOS(6_0);
- (NSUInteger)supportedInterfaceOrientations NS_AVAILABLE_IOS(6_0);
//(当shouldAutorotate返回YES时,调用第二个方法,设定支持方向)


如果是presentviewcontroller 会额外调用
preferredInterfaceOrientationForPresentation

注:如果要兼容4、5,则要实现shouldAutorotateToInterfaceOrientation方法,如上面所示代码。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: