iOS 7 Status Bar Collides With NavigationBar

前端 未结 17 1219
攒了一身酷
攒了一身酷 2020-11-28 03:14

I have a view controller in my app that has a navigation bar dragged on it in the storyboard. It was working fine in the iOS 6 but in iOS 7 it look like this:

相关标签:
17条回答
  • 2020-11-28 03:50

    You can probably create constraints that are attached to the top layout guide to specify the navigation bar's position relative to the status bar. See the iOS 7 UI Transition Guide: Appearance and Behavior section for more information about using the layout guides.

    0 讨论(0)
  • 2020-11-28 03:50

    If you use Xcode 6 and Swift, you can make it:

    1. Open to info.plist file of your app.
    2. Add a ViewControllerBasedStatusBarAppearance Boolean key if it is not existing and assign value “NO”.
    3. Add “Status bar style” key if it is not existing and select “Opaque black style” value to it.
    0 讨论(0)
  • 2020-11-28 03:51

    For the ones who are having problems implementing @Masterfego 's solution (which is also the official, but I have had problems with Xcode 6.3 and automatic constraints), this is what I did:

    I have a UIViewController with an added Navigation Bar. I selected the NAvigation bar and added a height constraint of 64px. We later see a warning that the navbar will be higher (but this is what we do). Finally, you can see that the Status bar looks nice and has the same color as the navbar. :)

    PS: I can't post images yet.

    0 讨论(0)
  • 2020-11-28 03:52

    First, set UIViewControllerBasedStatusBarAppearance to NO in Info.plist. Then, in AppDelegate's application:didFinishLaunchingWithOptions: method add:

    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
       [application setStatusBarStyle:UIStatusBarStyleLightContent];
       self.window.clipsToBounds = YES;
       self.window.frame = CGRectMake(0, 20, self.window.frame.size.width, self.window.frame.size.height-20);
       self.window.bounds = CGRectMake(0, 20, self.window.frame.size.width, self.window.frame.size.height);
     }
     return YES;
    
    0 讨论(0)
  • 2020-11-28 03:54

    in earlier iOS window start after statusbar and in iOS 7 window starts from 0px in earlier version view height is 460 (iPhone 4s and earlier) and 548 (iPhone 5) but in iOS 7 view height is 480 (iPhone 4s and earlier) and 568 (iPhone 5 and later) so you have to start view arrangement after 2o px or you have to start view from 20px.

    you can write below code in rootviewcontroller or in all viewcontroller for set view from 20px

    #define IOS7_HEIGHT             64
    
    - (void)viewDidLayoutSubviews {
        NSString *currSysVer = [[UIDevice currentDevice] systemVersion];
        if ([currSysVer compare:@"7.0" options:NSNumericSearch] != NSOrderedAscending)
        {
            CGRect frame=[self.view frame];
            if (frame.origin.y!=IOS7_HEIGHT) {
    
                frame.origin.y = IOS7_HEIGHT;
                frame.size.height -= IOS7_HEIGHT;
                [self.view setFrame:frame];
                [self.view layoutSubviews];
            }
        }
    }
    

    here height is 64 because 20 for statusbar and 44 for navigationbar. try below code it will help you. and your problem will be solved.

    0 讨论(0)
提交回复
热议问题