UIWebView under transparent UINavigationBar

前端 未结 6 1097
醉酒成梦
醉酒成梦 2021-02-09 21:30

I have a UIWebView which I want to put under my translucent UINavigationBar. Normally when I put a UIScrollView under a translucent UINavigationBar, I set its contentOffset such

6条回答
  •  终归单人心
    2021-02-09 22:27

    With the advent of iOS 7, the offset height would now need to include the height of the top status area. Otherwise, iOS7 devices will have 20 pixels of webview still hidden under the navigation bar.

    In a project that needs to support iOS 7 and older devices, a macro like the one found here:

    #define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
    

    Can be very useful. A modified version of zerotool's helpful code listed above could now look something like this:

    if (self.navigationController != nil && self.navigationController.navigationBar.translucent) {
        top = self.navigationController.navigationBar.bounds.size.height;
        if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) {
            top += [[UIScreen mainScreen] applicationFrame].origin.y;
        }
    }
    // (etc.)
    

提交回复
热议问题