iOS 7状态栏重叠UI

Aut*_*r21 49 iphone cordova ios7 xcode5

我最近升级到xcode 5,当我在iOS模拟器中运行我的应用程序时,启动画面与状态栏重叠,当你在应用程序中时状态栏重叠到我的应用程序上的元素,就像我左上角的后退按钮我的应用程序的一角.我使用phonegap 2.9构建我的应用程序.任何想法如何让我正确渲染.

闪屏

UI

Rom*_*nce 67

如果您正在使用故事板,则可以解决此问题,如此问题:iOS 7 - 状态栏与视图重叠

如果你不使用的故事板,那么您可以在您使用此代码AppDelegate.mdid finishlaunching:

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
    [application setStatusBarStyle:UIStatusBarStyleLightContent];
    self.window.clipsToBounds =YES;
    self.window.frame =  CGRectMake(0,20,self.window.frame.size.width,self.window.frame.size.height-20);
}
Run Code Online (Sandbox Code Playgroud)

另请参阅此问题:IOS7中的状态栏和导航栏问题

  • 嘿我的状态栏部分不可见.它的Balck使用此代码.你可以帮帮我吗? (7认同)
  • 请参阅此http://stackoverflow.com/a/19025547/1545180它可能会对您有所帮助. (2认同)

Gim*_*imi 50

MainViewController.m里面:- (void)viewWillAppear:(BOOL)animated添加:

//Lower screen 20px on ios 7
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
        CGRect viewBounds = [self.webView bounds];
        viewBounds.origin.y = 18;
        viewBounds.size.height = viewBounds.size.height - 18;
        self.webView.frame = viewBounds;
    }
Run Code Online (Sandbox Code Playgroud)

所以end函数看起来像这样:


- (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.
    //Lower screen 20px on ios 7
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
        CGRect viewBounds = [self.webView bounds];
        viewBounds.origin.y = 18;
        viewBounds.size.height = viewBounds.size.height - 18;
        self.webView.frame = viewBounds;
    }
    [super viewWillAppear:animated];
}
Run Code Online (Sandbox Code Playgroud)

  • 我遇到了与Ignacio相同的问题,在显示另一个原生视图(例如摄像头捕获对话框)然后导航回webView后,我的应用程序底部显示了一个白色条.每次显示/解除第二个原生对话时,白条都会增长.解决方法是将'viewBounds'初始化为'[self.view bounds]'而不是'[self.webView bounds]'. (12认同)
  • 这是phonegap/cordova应用程序的最佳解决方案.轻微的挑剔 - 你应该使用20而不是18? (4认同)
  • @JanDudek如果您使用`height = device-height`,您可以切换到`width = device-width`以获得与之前相同的效果,而不受状态栏更改的影响. (2认同)

Ger*_*sio 36

我通常做的是向Info.plist文件添加两个键值属性.

在此输入图像描述

属性源代码是:

在此输入图像描述

  • 这绝对是最容易实现的解决方案,也适合我. (4认同)

小智 9

我在打开带有phonegap的inApp浏览器时遇到了问题.Gimi的修复效果很好,但每次打开inApp浏览器时,屏幕都会在底部缩小.所以我添加了一个if语句来检查webview的y origin是否为0.InApp浏览器不再具有y origin 0,所以它解决了我的问题.

// ios 7 status bar fix
- (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.
    //Lower screen 20px on ios 7
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
        if(self.webView.frame.origin.y == 0) {
            CGRect viewBounds = [self.webView bounds];
            viewBounds.origin.y = 20;
            viewBounds.size.height = viewBounds.size.height - 20;
            self.webView.frame = viewBounds;
        }
    }

    [super viewWillAppear:animated];
}
Run Code Online (Sandbox Code Playgroud)

解决方案不是我的,但我找不到来源.希望能帮助到你!


Moe*_*ram 6

将此代码段放在MainViewController.mphonegap项目的文件中.

- (void)viewDidLayoutSubviews{

    if ([self respondsToSelector:@selector(topLayoutGuide)]) // iOS 7 or above
    {
        CGFloat top = self.topLayoutGuide.length;
        if(self.webView.frame.origin.y == 0){
            // We only want to do this once, or 
            // if the view has somehow been "restored" by other    code.
            self.webView.frame = CGRectMake(self.webView.frame.origin.x,
                                           self.webView.frame.origin.y + top,
                                           self.webView.frame.size.width,
                                           self.webView.frame.size.height-top);
        } 
    } 
}
Run Code Online (Sandbox Code Playgroud)


小智 5

我在ViewDidLoad方法中使用此代码.

 if ([self respondsToSelector:@selector(edgesForExtendedLayout)])
 {
    self.edgesForExtendedLayout = UIRectEdgeNone;
 }
Run Code Online (Sandbox Code Playgroud)

这在尝试支持以前的iOS版本时也有效.


jot*_*tav 5

如果您正在开发iOS 7,我不建议将状态栏包装在黑色矩形旧iOS风格中.只需将其集成到设计中,即可获得更多iOS 7"全屏"外观.

您可以使用此插件调整状态栏的墨水颜色,或隐藏它或在应用程序的任何实例中显示它.

https://github.com/jota-v/cordova-ios-statusbar

js方法是:

window.plugins.statusBar.hide();
window.plugins.statusBar.show();
window.plugins.statusBar.blackTint();
window.plugins.statusBar.whiteTint();
Run Code Online (Sandbox Code Playgroud)

重要提示:同样在您的应用程序plist文件中设置UIViewControllerBasedStatusBarAppearanceNO.


tru*_*old 5

实际上,我发现Gimi的答案是最好的答案,而且我一直在寻找很多东西!只是为了添加Gimi的答案,并回答ignacio-munizaga对该答案的回复,代码将在视图出现时执行,这意味着在您关闭内联浏览器之后,或在相机滚动等之后,所以我只是将bool值说明尺寸是否已经调整过.

最终代码如下:

bool sizeWasAdjusted = false;
- (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.
    //Lower screen 20px on ios 7
    if (!sizeWasAdjusted && [[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
        CGRect viewBounds = [self.webView bounds];
        viewBounds.origin.y = 18;
        viewBounds.size.height = viewBounds.size.height - 18;
        self.webView.frame = viewBounds;
        sizeWasAdjusted = true;
    }
    [super viewWillAppear:animated];
}
Run Code Online (Sandbox Code Playgroud)


dk1*_*123 5

尝试(app name)-Info.plist在XCode中进入应用程序的文件并添加密钥

view controller-based status bar appearance: NO
status bar is initially hidden : YES
Run Code Online (Sandbox Code Playgroud)

这对我来说似乎没有问题.