首页 文章

状态栏正在按下视图内容,仅当启动应用程序时激活了呼叫状态栏

提问于
浏览
6

所以我在这里有一些奇怪的行为 . 我有一个用Swift编码的基本iOS应用程序 . 它使用WKWebView以及其他一些小功能 .

目前的一个主要问题是“通话状态栏” . 如果我在应用程序打开时切换通话中状态栏,它看起来非常好:

enter image description here


虽然如果我在打开应用程序然后运行它之前切换调用状态栏,布局就会变得奇怪:

enter image description here


随着将状态栏切换为“关闭”,它甚至变得更奇怪(顶部的空白区域为20px):

enter image description here


即使在应用程序打开时切换了通话中状态栏,问题仍然存在,尽管我使用这个简单的单线程修复了这个(因此第一张图像看起来很好):

webView.autoresizingMask = [UIViewAutoresizing.FlexibleWidth, UIViewAutoresizing.FlexibleHeight]

即使在激活呼叫时应用程序处于打开状态,我如何才能使我的webview能够适应这种情况?

1 回答

  • 0

    我也遇到过这个问题,并通过在应用程序打开时检查状态栏的大小来解决它,如果它是40分然后监听 UIApplicationDidChangeStatusBarFrame 通知,当发生一个时,将视图框移动到 .zero .

    例如,在Swift 4中:

    var sbshown: Bool = false
    
    override func viewDidLoad() {
        super.viewDidLoad()
    
        //check height of status bar when app opens, and set a boolean if open
        let sbheight = UIApplication.shared.statusBarFrame.height
    
        NSLog("status bar height %f", sbheight)
    
        if (sbheight == 40) {
            sbshown = true
        }
    
        //set up to receive notifications when the status bar changes
        let nc = NotificationCenter.default 
    
        nc.addObserver(forName: NSNotification.Name.UIApplicationDidChangeStatusBarFrame, object: nil, queue: nil, using: statusbarChange)
    
    }
    

    然后实现一个方法来在状态栏消失时调整视图大小并重新定位视图:

    func statusbarChange(notif: Notification) -> Void {
    
         if (sbshown) {
             sbshown = false
    
             self.view.frame.origin = .zero
             self.view.frame.size.height = UIScreen.main.bounds.height
         }    
    
    }
    

    因此,重新定位应该仅在应用程序打开时已显示栏时发生,而不是在应用程序已打开时显示和隐藏栏时 .

相关问题