在你想支持横竖屏的viewController里面重写两个方法:
// 支持设备自动旋转- (BOOL)shouldAutorotate{ return YES;}// 支持横竖屏显示- (NSUInteger)supportedInterfaceOrientations{ return UIInterfaceOrientationMaskAll;}这样在这个viewController中就可以横竖屏切换了。
但是,如果你window的rootViewController是一个navigationController,可能会出现以下问题:
navigationController只支持竖屏,但是你push到了某个新的controller中,这个controller支持横竖屏,当你在新的controller中切换到横屏后(也有可能在切换到横屏然后pop回来后),这时候程序会闪退,因为你的navigationController不支持横屏。
这需要写一个UINavigationController的子类,在这个类中重写方法:
- (BOOL)shouldAutorotate{ return [self.viewControllers.lastObject shouldAutorotate];}- (NSUInteger)supportedInterfaceOrientations{ return [self.viewControllers.lastObject supportedInterfaceOrientations];}- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{ return [self.viewControllers.lastObject preferredInterfaceOrientationForPresentation];}原文地址:http://blog.csdn.net/u012460084/article/details/45500283