App中其它界面都是竖屏, 只有一个界面是需要横屏的, 怎样使这个界面强制横屏布局?
如果需要特定ViewController旋转, 可以为UINavigationController添加Category(类目)UINavigationController+InterfaceOrientation, 然后在指定的ViewController中调用即可.
@implementation UINavigationController (InterfaceOrientation)
- (BOOL)shouldAutorotate
{
if ([self.topViewController respondsToSelector:@selector(shouldAutorotate)]) {
return [self.topViewController shouldAutorotate];
}
return NO;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
if ([self.topViewController respondsToSelector:@selector(supportedInterfaceOrientations)]) {
return [self.topViewController supportedInterfaceOrientations];
}
return [super supportedInterfaceOrientations];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
if ([self.topViewController respondsToSelector:@selector(preferredInterfaceOrientationForPresentation)]) {
return [self.topViewController preferredInterfaceOrientationForPresentation];
}
return [super preferredInterfaceOrientationForPresentation];
}
@end
另外, 推荐一篇博文: http://www.molotang.com/articles/1530.html. 对于不同级别的屏幕旋转梳理的较为清晰.
那怎么保证其它界面始终是竖屏呢
使用如下这种方式,在需要横屏的页面添加。
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
return UIInterfaceOrientationIsLandscape(toInterfaceOrientation);
}