iOS 8: web app status bar position and resizing problems

后端 未结 8 1217
离开以前
离开以前 2020-12-07 19:04

When setting the meta tags

apple-mobile-web-app-capable

and

apple-mobile-web-app-status-bar-style

to

相关标签:
8条回答
  • 2020-12-07 19:16

    To expand on all of the above, my solution is:

    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
    

    Then create a custom CSS for all the elements that need to shift down by 20px, particularly any position: fixed; top: 0px; that exists in your CSS for normal browser [desktop/mobile] view.

    Add the custom CSS into the head section, below CSS links with the following script [my working example]

    <script type="text/javascript">
       if (window.navigator.standalone) {
           document.write("<link type=\"text\/css\" rel=\"stylesheet\" media=\"all\" href=\"assets/css/style-body-ios8.css\" charset=\"utf-8\" \/>");
    }
    </script>
    

    My result is desktop/mobile browser website view is as normal, then website added to home screen as a web app, on launch opens fullscreen, with status bar looking like it used to pre ios8 [fyi, I added a background color of black to my fixed header css for the status bar to show as black background

    Tested on iPad/iPhone/iPod running ios 8.0.2 - all good. FYI, tested on old iPod ios 6.1.6 expecting an extra shift down of 20px and wasn't there - bonus!

    0 讨论(0)
  • 2020-12-07 19:20

    Technically this is not an answer to your question, but I have been documenting my findings while trying to resolve this issue myself, and here is what I've found so far. I was going to post it as it's own question, but figured it would be closed as a duplicate.

    On iOS8 devices running pinned web applications. Regarding the tag :

    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    

    From the Apple developer reference:

    If content is set to default, the status bar appears normal. If set to black, the status bar has a black background. If set to black-translucent, the status bar is black and translucent. If set to default or black, the web content is displayed below the status bar. If set to black-translucent, the web content is displayed on the entire screen, partially obscured by the status bar. The default value is default.

    To enable this functionality, you need to use

    <meta name="apple-mobile-web-app-capable" content="yes">
    

    In iOS6 and 7 this works more or less as expected.

    In iOS8 this appears to be broken entirely. For example, iOS 8.0.2 running on an iPad Air in portrait has the following behaviour:

    • black results in a transparent background. There is a solid black bar at the bottom of the screen
    • default or not setting a value results in a transparent background and a solid white bar at the bottom of the screen
    • black-translucent results in a transparent background, but no annoying bars at the bottom of the screen

    In all cases, the content appears "beneath" the bar. i.e. the bar does not push content down.

    On an iPhone6, the status bar does not display at all in landscape. In portrait however, the following behaviour:

    • black works as expected, and content is pushed down (wow!!!)
    • default has an empty white bar at the top
    • black-translucent results in a transparent background, with content underneath

    I have not had the opportunity to test on an iPhone6+

    The iOS simulator in xcode does not appear to give reliable reproduction of the behaviour that occurs on real devices.

    I have tried changing it dynamically with javascript, but it appears to have no effect.

    Just to make this even more interesting/frustrating, you can COVER the status bar (clock/wifi etc) by setting styles on the html element. e.g.

      html {background: black;}
      body {background: #DDD; margin-top: 20px}
    

    The same issue documented elsewhere:

    • https://discussions.apple.com/thread/6557230?start=0&tstart=0
    0 讨论(0)
  • 2020-12-07 19:22

    The issue comes from using <meta name="apple-mobile-web-app-status-bar-style" content="black">In order to get rid of the black bar at the bottom of your app, you will need to use:<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent"> Using black-translucent will keep your app looking the same in both iOS7 and iOS8. You will still need to adjust any content at the top of your app to clear the iOS status bar icons.

    0 讨论(0)
  • 2020-12-07 19:26

    Apple fixed this bug in iOS 8.3 beta 1

    0 讨论(0)
  • 2020-12-07 19:28

    Just add a 20px high div to the top of your app and let that act as that status bar

    0 讨论(0)
  • 2020-12-07 19:30

    It is worth noting that setting the status bar style to 'black' is working as expected as long as you open the Web App with your iPad in Portrait. Then even if you rotate the iPad the black bar is correctly visible.

    The problem is only when you enter the Web App in landscape, at least for me. I am using iPad 3 with IOS 8.1, and I believe it is still the same in 8.3

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