ios 单个ViewController屏幕旋转

如果需要旋转的ViewController 使用了UINavigationController,对UINavigationController进行如下扩展

复制代码
@implementation UINavigationController(shouldAutorotate)
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation == UIInterfaceOrientationPortrait); }
- (BOOL)shouldAutorotate { return self.topViewController.shouldAutorotate; }
- (NSUInteger)supportedInterfaceOrientations { return self.topViewController.supportedInterfaceOrientations; } @end
复制代码

需要旋转的ViewController设置

复制代码
 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
    return YES;
}

- (BOOL)shouldAutorotate
{
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAll;
}
复制代码

 

其他不需要旋转的 ViewController设置,建议添加BaseViewController统一控制

复制代码
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (BOOL)shouldAutorotate
{
    return NO;
}
- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationPortrait;
}
复制代码

 

posted @   geweb  阅读(963)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示