03_知识点_横竖屏适配

如果需要大部分界面只支持竖屏,部分页面支持横屏,需要这样写:

如果这几个方法不起作用,那么估计是你的viewcontroller加在了nav中或tab中,再或者加入nav然后nav加入了tab,那么就要重写nav或tab的这三个方法:

tab中:

- (BOOL)shouldAutorotate{

return [[self.viewControllers objectAtIndex:(int)self.selectedIndex] shouldAutorotate];

}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations{

return [[self.viewControllers objectAtIndex:(int)self.selectedIndex] supportedInterfaceOrientations];

}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{

return [[self.viewControllers objectAtIndex:(int)self.selectedIndex] preferredInterfaceOrientationForPresentation];

}

nav中:

- (BOOL)shouldAutorotate{

return [self.viewControllers.lastObject shouldAutorotate];

}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations{

return [self.viewControllers.lastObject supportedInterfaceOrientations];

}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{

return [self.viewControllers.lastObject preferredInterfaceOrientationForPresentation];

}

最后在需要横屏或竖屏的controller中再重写以上三个方法。

你可能感兴趣的:(03_知识点_横竖屏适配)