美文网首页
iOS setStatusBarOrientation 无效的解

iOS setStatusBarOrientation 无效的解

作者: en_nina | 来源:发表于2017-06-17 15:36 被阅读189次

title: iOS setStatusBarOrientation 无效的解决方法
date: 2016-06-08 01:00:30
categories: "iOS"
tags:

  • Objective-C

1、window.rootViewController 为VC的时候 下面两种情况改方法仍须在VC中重写

//控制器中重写
- (BOOL)shouldAutorotate {
    return NO;
}

2、window.rootViewController 为nav的时候

//UINavigationController 子类或者分类中重写一下方法
- (BOOL)shouldAutorotate {
    return [self.visibleViewController shouldAutorotate];
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
    return [self.visibleViewController supportedInterfaceOrientations];
}


- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return [self.visibleViewController preferredInterfaceOrientationForPresentation];
}

3、window.rootViewController 为tabBar的时候

//UITabBarController 子类或者分类中重写一下方法
- (BOOL)shouldAutorotate {
    return self.selectedViewController.shouldAutorotate;
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
    return self.selectedViewController.supportedInterfaceOrientations;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return [self.selectedViewController preferredInterfaceOrientationForPresentation];
}

- (UIStatusBarStyle)preferredStatusBarStyle {
    return [self.selectedViewController preferredStatusBarStyle];
}

如果想更改状态栏的颜色需要一下设置

需要在info.Plist 添加 View controller-based status bar appearance 设置成No,默认为Yes

原文地址: http://oxy.pub

相关文章

网友评论

      本文标题:iOS setStatusBarOrientation 无效的解

      本文链接:https://www.haomeiwen.com/subject/qqfbqxtx.html