iOS 7 Status Bar Collides With NavigationBar

前端 未结 17 1274
攒了一身酷
攒了一身酷 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: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.

提交回复
热议问题