在iOS 7中,Phonegap应用程序将出现在状态栏下面。这可能会使位于屏幕顶部的按钮/菜单难以点击。
是否有人知道如何在Phonegap应用程序中修复iOS 7上的状态栏问题?
我已经尝试使用CSS偏移整个网页,但似乎不起作用。是否有一种方法可以像在iOS 6中一样改变整个UIWebView的偏移量或只是让状态栏的行为像以前一样?
谢谢
在iOS 7中,Phonegap应用程序将出现在状态栏下面。这可能会使位于屏幕顶部的按钮/菜单难以点击。
是否有人知道如何在Phonegap应用程序中修复iOS 7上的状态栏问题?
我已经尝试使用CSS偏移整个网页,但似乎不起作用。是否有一种方法可以像在iOS 6中一样改变整个UIWebView的偏移量或只是让状态栏的行为像以前一样?
谢谢
20px
的边距。请确保已安装“device”插件,并且此代码位于“deviceready”事件内。从阅读中得知,据说Phonegap的下一个更新(我认为是3.1)将更好地支持iOS7状态栏的更改。因此,这可能只需要作为短期解决方案。if(window.device && parseFloat(window.device.version) >= 7){
document.body.classList.add('fix-status-bar');
}
@interface MainViewController : CDVViewController
@property (atomic) NSInteger landscapeOriginalSize;
@property (atomic) NSInteger portraitOriginalSize;
@end
MainViewController.m
文件中:@implementation MainViewController
@synthesize landscapeOriginalSize;
@synthesize portraitOriginalSize;
...
- (void)viewWillAppear:(BOOL)animated
{
// View defaults to full size. If you want to customize the view's size, or its subviews (e.g. webView),
// you can do so here.
[super viewWillAppear:animated];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil];
}
- (void)orientationChanged:(NSNotification *)notification {
[self adjustViewsForOrientation:[[UIApplication sharedApplication] statusBarOrientation]];
}
- (void)viewDidDisappear:(BOOL)animated {
[[NSNotificationCenter defaultCenter]removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil];
}
- (void) adjustViewsForOrientation:(UIInterfaceOrientation) orientation {
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
CGRect statusBarFrame = [UIApplication sharedApplication].statusBarFrame;
CGRect frame = self.webView.frame;
switch (orientation)
{
case UIInterfaceOrientationPortrait:
case UIInterfaceOrientationPortraitUpsideDown:
{
if (self.portraitOriginalSize == 0) {
self.portraitOriginalSize = frame.size.height;
self.landscapeOriginalSize = frame.size.width;
}
frame.origin.y = statusBarFrame.size.height;
frame.size.height = self.portraitOriginalSize - statusBarFrame.size.height;
}
break;
case UIInterfaceOrientationLandscapeLeft:
case UIInterfaceOrientationLandscapeRight:
{
if (self.landscapeOriginalSize == 0) {
self.landscapeOriginalSize = frame.size.height;
self.portraitOriginalSize = frame.size.width;
}
frame.origin.y = 0;
frame.size.height = self.landscapeOriginalSize;
}
break;
case UIInterfaceOrientationUnknown:
break;
}
self.webView.frame = frame;
}
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
// Change this color value to change the status bar color:
self.view.backgroundColor = [UIColor colorWithRed:0/255.0f green:161/255.0f blue:215/255.0f alpha:1.0f];
}
这是我在这个和相关的StackOverflow讨论中发现的结合体,一些来自Cordova StatusBar插件的代码(以避免硬编码20px值),以及我自己的一些咒语(我不是iOS开发人员,所以我摸索着找到了这个解决方案)。
控制状态栏背景的最佳方法 - 2017
在经历了持续的挫折和大量互联网搜索之后,这些是您需要采取的步骤:
< preference name="StatusBarOverlaysWebView" value="false" />
在 onDeviceReady 中使用以下代码:
StatusBar.show();
StatusBar.overlaysWebView(false);
StatusBar.backgroundColorByHexString('#209dc2');
在iOS和Android上对我有效。
祝你好运!
function mytopmargin() {
console.log("PLATform>>>" + device.platform);
if (device.platform === 'iOS') {
$("div[data-role='header']").css("padding-top", "21px");
$("div[data-role='main']").css("padding-top", "21px");
} else {
console.log("android");
}
}
在AppDelegate.m文件中的didFinishLaunchingWithOptions事件里写入以下代码(恰好在最后一行代码"return YES;"之前):
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7)
{
[application setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
}
我会等待您的反馈!:)
如果我们使用相机插件来创建图库,状态栏将会出现问题,为了解决这个问题,请添加这行代码
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
到
- (void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary*)info {...}
插件列表中CVDCamera.m内部的函数
在AppDelegate.m文件中,在didFinishLaunchingWithOptions事件的开头编写以下代码。
CGRect screenBounds = [[UIScreen mainScreen] bounds];
// 修复状态栏 -------------------------------
NSArray *vComp = [[UIDevice currentDevice].systemVersion componentsSeparatedByString:@"."];
if ([[vComp objectAtIndex:0] intValue] >= 7) { // iOS 7或以上版本
CGRect newWebViewBounds = CGRectMake( 0, 20, screenBounds.size.width, screenBounds.size.height-20 );
screenBounds = newWebViewBounds;
}
// ------------------------------- 修复状态栏结束
并且适用于iOS 7及以上版本的修复。