加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

如何在iOS半透明中制作PhoneGap状态栏?

发布时间:2020-12-14 17:38:54 所属栏目:百科 来源:网络整理
导读:我正在使用PhoneGap来构建iOS应用程序,似乎无法使全屏/半透明状态栏效果起作用. 我将* -info.plist的状态栏样式设置为透明黑色样式(alpha为0.5),在启动画面启动时可以正常工作.但是,当显示PhoneGap的UIWebView时,状态栏会变黑. 我尝试在我的index.html中将ap
我正在使用PhoneGap来构建iOS应用程序,似乎无法使全屏/半透明状态栏效果起作用.

我将* -info.plist的状态栏样式设置为透明黑色样式(alpha为0.5),在启动画面启动时可以正常工作.但是,当显示PhoneGap的UIWebView时,状态栏会变黑.

我尝试在我的index.html中将apple-mobile-web-app-status-bar风格的元标记设置为黑色半透明,但这似乎没有任何效果.

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

解决方法

实际上状态栏是半透明的.

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读