在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方法,如上面所示代码。