iOS7 hide status bar but not adjust top layout guide

我与影子孤独终老i 提交于 2020-01-21 06:29:25

问题


I deal with autolayout set up in Interface Builder. I want to not offset views that are pinned to top layout guide when I hide status bar in runtime.

I have discovered that myViewController.topLayoutGuide.length changes from 20 to 0 when hiding status bar. How to prevent it? Or (as workaround) how to set up fullscreen view for various window sizes without pin to top layout guide?

Some code to describe my situation:

Log(@"frame: %@, top: %.0f", NSStringFromCGRect(myViewController.myView.frame), self.topLayoutGuide.length);
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
Log(@"frame: %@, top: %.0f", NSStringFromCGRect(myViewController.myView.frame), self.topLayoutGuide.length);

Output:

frame: {{40, 24}, {240, 40}}, top: 20
frame: {{40, 4}, {240, 40}}, top: 0

回答1:


The topLayoutGuide property is readonly and you can't prevent it from changing.

You can pin your items not to the topLayoutGuide but to the superview. That should resolve your problem.



来源:https://stackoverflow.com/questions/21756350/ios7-hide-status-bar-but-not-adjust-top-layout-guide

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!