How can I get the iOS status bar to *overlay* the app surface rather than pushing it down?

烈酒焚心 提交于 2019-12-13 05:29:49

问题


I am developing a Phonegap app for iOS (and others). The view is landscape only. I am using Phonegap Build with PG 3.1. I am testing on an iPad3 with iOS7. I need a solution that works not just on iOS7, but also a couple of versions back.

In the Xcode iPad emulator, the app uses the entire screen. The status bar is transparent and overlaid on top of the app. However, when I test the app on my iPad, the status bar isn't transparent anymore, and pushes the app down 20px, which means the bottom 20px disappear.

For this particular app, it would be much better if the top was overlaid, so that the important bottom part of the app wasn't pushed out of view. So the question is: Can I either make the status bar disappear completely, or can I make it transparent and overlaid?

I have tried the Status Bar plugin for Phonegap, but it doesn't seem to work properly. I used StatusBar.hide() in my deviceReady function, but the bar remained in view. And worse, the right-hand part of the screen became completely unresponsive to touch events. As if there was a transparent overlay on that part of the screen, possibly related to this bug. As described there, the overlay isn't transparent though, but it seems to cover exactly the same area that goes unresponsive in my case.


回答1:


I got this to work beautifully in Cordova 3.6 + iOS 7.1. And considering that iOS 7 and 8 each have 50% of market share this solution should be enough.

Plugin I'm using: org.apache.cordova.statusbar

Instead of using StatusBar.hide() I used:

var hideSb = function(){
//        StatusBar.hide;
        cordova.exec(null, null, 'StatusBar', 'hide', ['Ehi', 'You']);
    };

Call it in fn onDeviceReady. And this is based on:

cordova.exec(
    callbackFn,     // A callback function that deals with the JSON object from the CDVPluginResult instance
    errorFn,        // An error handler
    'TargetClass',  // What class to target messages to (method calls = message in ObjC)
    'methodToCall', // Which method to call
    [ 'array', 'of', 'arguments'] // These go in the CDVInvokedUrlCommand instance's.arguments property
);

And I've experienced that wrapping it in a function works and just using it straight away doesn't work at times. Also I'm clueless about the arguments passed!



来源:https://stackoverflow.com/questions/20716753/how-can-i-get-the-ios-status-bar-to-overlay-the-app-surface-rather-than-pushin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!