[英]How to make PhoneGap status bar in iOS translucent?
I'm using PhoneGap to build an iOS app and can't seem to get that full-screen/translucent status bar effect to work. 我正在使用PhoneGap来构建iOS应用程序,似乎无法使全屏/半透明状态栏效果起作用。
I set the *-info.plist's Status bar style
to Transparent black style (alpha of 0.5)
, which works while the splash screen is up. 我将* -info.plist的
Status bar style
为Transparent black style (alpha of 0.5)
,在启动画面启动时可以正常工作。 But the status bar turns black when PhoneGap's UIWebView is displayed. 但是,当显示PhoneGap的UIWebView时,状态栏会变黑。
I tried setting the apple-mobile-web-app-status-bar-style
meta tag to black-translucent
in my index.html, but that doesn't seem to have any effect. 我尝试在我的index.html中将
apple-mobile-web-app-status-bar-style
元标记设置为black-translucent
,但这似乎没有任何效果。
I tried setting phonegap.plist's TopStatusBar
option to blackTranslucent
, but that didn't have any effect either. 我尝试将phonegap.plist的
TopStatusBar
选项设置为blackTranslucent
,但这也没有任何效果。 What am I missing? 我错过了什么?
Actually the Status Bar is translucent. 实际上状态栏是半透明的。
- (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 log result of this code shows: 此代码的日志结果显示:
The WebView: 0.000000 0.000000 320.000000 460.000000
The WebView superview: 0.000000 20.000000 320.000000 460.000000
so fixing the webview.superview frame you can get the effect of UIStatusBarTranslucent 所以修复webview.superview框架可以获得UIStatusBarTranslucent的效果
CGRect frame = theWebView.superview.frame;
frame.size.height += frame.origin.y;
frame.origin.y = 0;
[theWebView.superview setFrame:frame];
You can try to add in your Info.plist for your app: 您可以尝试在应用中添加Info.plist:
Key: Status bar style
Value: Black translucent style
or if you are using raw key value pairs 或者如果您使用原始键值对
<key>UIStatusBarStyle</key>
<string>UIStatusBarStyleBlackTranslucent</string>
This answer is adapted from another given by mwbrooks for a similar question. 这个答案改编自mwbrooks针对类似问题给出的另一个答案。 Give it a try.
试试看。
( Phonegap - How do i make the statusbar black? ) ( Phonegap - 如何使状态栏变黑? )
Or maybe, in your (void)viewDidLoad method of your **AppDelegate.m, you can put: 或者,也许,在您的** AppDelegate.m的(void)viewDidLoad方法中,您可以放置:
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleBlackTranslucent;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.