我正在使用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];