Rud*_*vič 15 uiviewcontroller ios uistatusbar autolayout
我想询问有关自动布局和通话状态栏的信息.这是一个简单的场景,演示了我的问题:
表视图应具有4个布局约束(前导,顶部,尾部,底部)到Superview,常量设置为0.
现在,当我在模拟器中运行此应用程序并按⌘+时,T我可以看到红色背景,而在通话状态栏动画.是否有可能摆脱这个故障?
(由于缺乏声誉而使用答案而不是评论,抱歉.)
我也遇到了这个问题并试图解决上面提到的解决方案:它对我不起作用.
所以我创建了一个包含示例代码的存储库来公开原始海报的问题.这些场景有示例应用程序:
事实证明,当自定义视图控制器是UINavigationController的子代(案例2和4)时,CEarwood的解决方案实际上有效.Hoewever,它在案例1和3中不起作用.
我希望这些信息有用.
对于纯粹的自动布局答案,您可以获得对底部约束的引用,并在收到UIApplicationWillChangeStatusBarFrameNotification时调整其常量,并在收到DidChange通知时返回0.这是我使用的测试VC:
@interface CEViewController ()
@property (nonatomic, strong) IBOutlet NSLayoutConstraint *bottomConstraint;
@end
@implementation CEViewController
- (void)viewDidLoad {
    [super viewDidLoad];        
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(statusBarFrameWillChange:) name:UIApplicationWillChangeStatusBarFrameNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(statusBarFrameDidChange:) name:UIApplicationDidChangeStatusBarFrameNotification object:nil];
}
- (void)statusBarFrameWillChange:(NSNotification *)note {
    NSValue *newFrameValue = [note userInfo][UIApplicationStatusBarFrameUserInfoKey];
    self.bottomConstraint.constant = newFrameValue.CGRectValue.size.height;
    [self.view setNeedsLayout];
}
- (void)statusBarFrameDidChange:(NSNotification *)note {
    self.bottomConstraint.constant = 0;
    [self.view setNeedsLayout];
}
@end
| 归档时间: | 
 | 
| 查看次数: | 9576 次 | 
| 最近记录: |