简体   繁体   English

iOS状态栏和UIView

[英]iOS status bar and UIView

There is UIView, status bar, iOS 7 and iOS 6. With iOS 6 everything is good: my UIView (transparent, under "Tap to set destination" label) appears right below status bar. 有UIView,状态栏,iOS 7和iOS 6.使用iOS 6一切都很好:我的UIView(透明,在“点击设置目的地”标签下)出现在状态栏的正下方。 Here is the picture: 这是图片:

在此输入图像描述

The problem is with iOS 7. Here: 问题出在iOS 7上。这里:

在此输入图像描述

I expect that UIView will be under status bar, not beneath it. 我希望UIView将处于状态栏下,而不是在它之下。 I have already tried to detect iOS version and if it's 7 or upper change UIView frame programmatically. 我已经尝试检测iOS版本,如果是7或更高版本以编程方式更改UIView框架。 But my UI with all the constraints made in storyboard... So it did not help. 但我的UI在故事板中有所有限制......所以它没有帮助。 What can I do to resolve this problem? 我该怎么做才能解决这个问题?

UPD: maybe I really should make design more capable for iOS7? UPD:也许我真的应该让设计更适合iOS7? I'll think about it, and thanks for recommendations! 我会考虑一下,并感谢您的推荐!

In your View Controller viewDidLoad , you should add: 在View Controller viewDidLoad ,您应该添加:

if (([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)) {
    [self setEdgesForExtendedLayout:UIRectEdgeNone];
}

If you really really need to do this you can place the map view inside another view that will be the root view of the controller. 如果您确实需要这样做,可以将地图视图放在另一个视图中,该视图将是控制器的根视图。 This root view will be under the status bar in iOS 6 and take full screen in iOS 7. Set black background for the root view. 此根视图将位于iOS 6中的状态栏下,并在iOS 7中全屏显示。为根视图设置黑色背景。

Add constrains from this root view to the map view and in viewDidLoad: check iOS version. 将此根视图中的约束添加到地图视图和viewDidLoad:检查iOS版本。 In iOS 7 change top constrain from 0 to the status bar height (or add contain to topLayoutGuide and remove the top constrain). 在iOS 7中,将顶部约束从0更改为状态栏高度(或添加包含到topLayoutGuide并删除顶部约束)。

But again the behavior you see is normal for iOS 7, and trying to make you view under the status bar you make your app look old-fashioned. 但是你再次看到的行为对于iOS 7来说是正常的,并且试图让你在状态栏下查看你让你的应用看起来过时了。 May be it's time to reconsider you design. 可能是时候重新考虑你的设计了。

In iOS 7 that's the default behavior of status bar. 在iOS 7中,这是状态栏的默认行为。 I guess the easiest solution will be to hide the status bar all together. 我想最简单的解决方案就是隐藏状态栏。

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    if ([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]) {
        // iOS 7
        [self prefersStatusBarHidden];
        [self performSelector:@selector(setNeedsStatusBarAppearanceUpdate)];
    } else {
        // iOS 6
        [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
    }

}

// Add this Method
- (BOOL)prefersStatusBarHidden
{
    return YES;
}

Try many ways, I saw dozens of post. 尝试了很多方法,我看了几十个帖子。 Finally this is the best solution I found. 最后,这是我找到的最佳解决方案。

Proper way to hide status bar on iOS, with animation and resizing root view 在iOS上隐藏状态栏的正确方法,包括动画和调整根视图的大小

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM