View got hidden below UINavigationBar iOS 7

前端 未结 9 1589
粉色の甜心
粉色の甜心 2020-12-02 13:10

Earlier, I was using iOS 6.1 for my project. Recently I have switched to iOS 7. For, a lot of changes I knew, I updated my code.. But I have observed a strange behavior. My

9条回答
  •  时光说笑
    2020-12-02 13:21

    Try navigationBar.translucent = NO;, It is YES by default in iOS7.

    It is also good to take a look on this part of UINavigationBar documentation:

    New behavior on iOS 7. Default is YES. You may force an opaque background by setting the property to NO. If the navigation bar has a custom background image, the default is inferred from the alpha values of the image—YES if it has any pixel with alpha < 1.0 If you send setTranslucent:YES to a bar with an opaque custom background image it will apply a system opacity less than 1.0 to the image. If you send setTranslucent:NO to a bar with a translucent custom background image it will provide an opaque background for the image using the bar's barTintColor if defined, or black for UIBarStyleBlack or white for UIBarStyleDefault if barTintColor is nil.

    Edit:

    Setting 'navigationBar.translucent' value causes exception if you run project in devices/simulators having older iOS versions.

    So you can add a version check like this:

    float systemVersion = [[[UIDevice currentDevice] systemVersion] floatValue];
    if (systemVersion >= 7.0)
    {
        navigationBar.translucent = NO;
    }
    

    Another option would be to set:

    vc.edgesForExtendedLayout = UIRectEdgeNone;
    

    Swift 3:

    vc.edgesForExtendedLayout = []
    

提交回复
热议问题