Best Practice to handle the extended height status bar with a WantsFullScreenLayout app?

淺唱寂寞╮ 提交于 2019-12-10 18:20:00

问题


In an app which has the wantsFullScreenLayoutset to YES, what is the best practice to handle an extended height status bar, i.e. with the extra status bar presented when a phone call or a VoIP app is present, or when the personal hotspot feature is activated?

Is the UIApplicationWillChangeStatusBarOrientationNotification notification (or the corresponding delegate method of UIApplication the right way to do it, or am I overlooking something obvious?

I have put up a little sample project here to demonstrate the issue.

Thanks

Alex


回答1:


The status bar with extended height can only be shown on iPhone or iPod in Portrait orientation.

You can get notified when the status bar frame will change using the UIApplicationWillChangeStatusBarFrameNotification (not UIApplicationWillChangeStatusBarOrientationNotification). This notification will also be posted when the interface orientation changes. On a frame change you could re-layout the views manually. Take the value of [UIApplication sharedApplication].statusBarFrame.size.height into account. It is 40 points in case of the extended status bar.

However, it is much simpler to hide the status bar completely for fullscreen view controllers so that the view can take advantage of the full display:

[UIApplication sharedApplication].statusBarHidden = NO;

You could also do something similar like in the photos app: Use the translucent status bar style and let the user hide the status bar with a single tap or hide it automatically after some time (when the user is not interacting with the app). This should be animated. Use the method setStatusBarHidden:withAnimation:.

Note that wantsFullScreenLayoutis a view controller property and not a property of UIApplication. You need to be careful when not all view controllers are presented in full screen mode.


From the Apple documentation:

wantsFullScreenLayout

A Boolean value indicating whether the view should underlap the status bar.

@property(nonatomic, assign) BOOL wantsFullScreenLayout

Discussion

When a view controller presents its view, it normally shrinks that view so that its frame does not overlap the device’s status bar. Setting this property to YES causes the view controller to size its view so that it fills the entire screen, including the area under the status bar. (Of course, for this to happen, the window hosting the view controller must itself be sized to fill the entire screen, including the area underneath the status bar.) You would typically set this property to YES in cases where you have a translucent status bar and want your view’s content to be visible behind that view.

If this property is YES, the view is not resized in a way that would cause it to underlap a tab bar but is resized to underlap translucent toolbars. Regardless of the value of this property, navigation controllers always allow views to underlap translucent navigation bars.

The default value of this property is NO, which causes the view to be laid out so it does not underlap the status bar.

This answer applies up to iOS 6, I'll update this post when iOS 7 is available.



来源:https://stackoverflow.com/questions/17118536/best-practice-to-handle-the-extended-height-status-bar-with-a-wantsfullscreenlay

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