如何使iOS上的PhoneGap状态栏半透明?

4
我正在使用PhoneGap构建iOS应用程序,但似乎无法实现全屏/半透明状态栏效果。
我已将*-info.plist的“状态栏样式”设置为“半透明黑色样式(透明度为0.5)”,这在闪屏界面上起作用。 但是,当PhoneGap的UIWebView显示出来后,状态栏变成了黑色。
我尝试在index.html中设置“apple-mobile-web-app-status-bar-style”元标签为“black-translucent”,但似乎没有任何效果。
我尝试将phonegap.plist的“TopStatusBar”选项设置为“blackTranslucent”,但也没有任何效果。 我错过了什么吗?
2个回答

4

实际上,状态栏是半透明的。

- (void)webViewDidFinishLoad:(UIWebView *)theWebView 
{
    // only valid if StatusBarTtranslucent.plist specifies a protocol to handle
    if(self.invokeString)
    {
        // this is passed before the deviceready event is fired, so you can access it in js when you receive deviceready
        NSString* jsString = [NSString stringWithFormat:@"var invokeString = \"%@\";", self.invokeString];
        [theWebView stringByEvaluatingJavaScriptFromString:jsString];
    }

    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleBlackTranslucent;

    CGRect frame = theWebView.frame;
    NSLog(@"The WebView: %f %f %f %f", frame.origin.x, frame.origin.y, frame.size.width, frame.size.height);
    frame = theWebView.superview.frame;
    NSLog(@"The WebView superview: %f %f %f %f", frame.origin.x, frame.origin.y, frame.size.width, frame.size.height);

    frame.size.height += frame.origin.y;
    frame.origin.y = 0;

    [theWebView.superview setFrame:frame];

    return [ super webViewDidFinishLoad:theWebView ];
}

这段代码的日志结果显示:
The WebView: 0.000000 0.000000 320.000000 460.000000
The WebView superview: 0.000000 20.000000 320.000000 460.000000

所以,通过修复webview.superview框架,您可以获得UIStatusBarTranslucent的效果。
CGRect frame = theWebView.superview.frame;

frame.size.height += frame.origin.y;
frame.origin.y = 0;

[theWebView.superview setFrame:frame];

Thats it :) Thanks Esepakuto. - paulcol.

1

您可以尝试在应用的 Info.plist 中添加以下内容:

Key: Status bar style
Value:  Black translucent style

或者如果您正在使用原始键值对

<key>UIStatusBarStyle</key>  
<string>UIStatusBarStyleBlackTranslucent</string> 

这个答案是从mwbrooks为类似问题提供的另一个答案中改编而来的。试试看。

( Phonegap - 如何使状态栏变黑? )

或者,你可以在你的**AppDelegate.m的(void)viewDidLoad方法中加入:

[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleBlackTranslucent;

感谢您的回复,maujee。好吧,*.plist 的解决方案似乎只适用于默认或黑色设置的渲染应用程序,不幸的是对于半透明并不起作用。我尝试在所有 AppDelegate.m 函数中使用代码,但似乎被覆盖了,又变成了黑色。 - paulcol.

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接