【问题标题】:How to make PhoneGap status bar in iOS translucent?如何使iOS中的PhoneGap状态栏半透明?
【发布时间】:2012-01-20 15:53:37
【问题描述】:

我正在使用 PhoneGap 构建 iOS 应用,但似乎无法让全屏/半透明状态栏效果发挥作用。

我将 *-info.plist 的 Status bar style 设置为 Transparent black style (alpha of 0.5),这在启动屏幕启动时有效。但是显示PhoneGap的UIWebView时状态栏变黑。

我尝试在我的 index.html 中将 apple-mobile-web-app-status-bar-style 元标记设置为 black-translucent,但这似乎没有任何效果。

我尝试将 phonegap.plist 的 TopStatusBar 选项设置为 blackTranslucent,但这也没有任何效果。我错过了什么?

【问题讨论】:

    标签: ios xcode cordova


    【解决方案1】:

    其实状态栏是半透明的。

    - (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];
    

    【讨论】:

    • 就是这样 :) 谢谢 Esepakuto。
    【解决方案2】:

    您可以尝试为您的应用添加 Info.plist:

    Key: Status bar style
    Value:  Black translucent style
    

    或者如果您使用的是原始键值对

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

    此答案改编自 mwbrooks 针对类似问题给出的另一个答案。试一试。

    (Phonegap - How do i make the statusbar black?)

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

    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleBlackTranslucent;
    

    【讨论】:

    • 感谢您的回复。好的 'ol *.plist 解决方案似乎只适用于默认或黑色设置的渲染应用程序,不幸的是不适用于半透明。我尝试了所有 AppDelegate.m 函数中的代码,但它似乎被覆盖了,又闪回黑色。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-22
    • 2019-06-27
    • 1970-01-01
    • 2017-07-07
    • 1970-01-01
    • 2016-04-18
    相关资源
    最近更新 更多