在应用中,我们有时需要将单独的一个页面强制横屏,而其他页面还是保持竖屏显示。在强制横屏时,我走了一点弯路,希望可以帮助到和我一样的小白O(∩_∩)O哈哈~
ios6+的系统下在强制横屏时,需要在controller中实现下面三个方法。
-(BOOL)shouldAutorotate //是否自动旋转
{
return NO;
}
-(NSUInteger)supportedInterfaceOrientations//controller支持的方向
{
return UIInterfaceOrientationMaskLandscape;
}
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation//默认的方向
{
return UIInterfaceOrientationLandscapeRight;
}
但是有时候我们会发现系统不会调用方法。后来看到一位大神的文章,恍然大悟。原来,如果你的controller添加了navgationcontroller,那么系统会去调用navgationcontroller里面的这些方法而忽略controller里的这些方法。值得注意!!!
有时我们会遇到这个错误,preferredInterfaceOrientationForPresentation must return a supported interface orientation!'也是由于这个原因和supportinterface共同造成的。