ios - 如何使 iOS 中的 PhoneGap 状态栏变为半透明?

标签 ios xcode cordova

我正在使用 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,但这也没有任何效果。我错过了什么?

最佳答案

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

- (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 frame就可以得到UIStatusBarTranslucent的效果

CGRect frame = theWebView.superview.frame;

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

[theWebView.superview setFrame:frame];

关于ios - 如何使 iOS 中的 PhoneGap 状态栏变为半透明?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8511845/

相关文章:

php - 使用 AFNetworking 从 ios 中的照片库上传图像?

ios - 如何像Instagram那样在矩形中创建透明圆圈?

ios - React Native iOS Release 构建停留在旧代码上,但 Debug 构建工作正常

ios - pointInside :withEvent inside uibezierpath (overlapping area between two views)

java - 如何使用 Phonegap Android 截图插件旋转截图图像

javascript - 无法克隆 <template> 以附加到 <div>

ios - 简单的应用程序,错误 "this class is not key value coding-compliant for the key "

ios - 部署到 iOS 4.x 时,ARC 可以安全使用吗?

ios - 相机控件未在设备上显示

android - 如何使用 Phonegap 跟踪设备位置(iOS 和 Android)设备