Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
373 views
in Technique[技术] by (71.8m points)

ios - UIViewController In-Call Status Bar Issue

Issue:

Modally presented view controller does not move back up after in-call status bar disappears, leaving 20px empty/transparent space at the top.


Normal : No Issues

enter image description here


In-Call : No Issues

enter image description here


After In-Call Disappears:

Leaves a 20px high empty/transparent space at top revealing orange view below. However the status bar is still present over the transparent area. Navigation Bar also leaves space for status bar, its' just 20px too low in placement.

enter image description here

enter image description here


  • iOS 10 based
  • Modally presented view controller
  • Custom Modal Presentation
  • Main View Controller behind is orange
  • Not using Autolayout
  • When rotated to Landscape, 20px In-Call Bar leaves and still leaves 20px gap.
  • I opt-out showing status bar in landscape orientations. (ie most stock apps)

I tried listening to App Delegates:

willChangeStatusBarFrame
didChangeStatusBarFrame

Also View Controller Based Notifications:

UIApplicationWillChangeStatusBarFrame
UIApplicationDidChangeStatusBarFrame

When I log the frame of presented view for all four above methods, the frame is always at (y: 0) origin.


Update

View Controller Custom Modal Presentation

    let storyboard = UIStoryboard(name: "StoryBoard1", bundle: nil)
    self.modalVC = storyboard.instantiateViewController(withIdentifier: "My Modal View Controller") as? MyModalViewController
    self.modalVC!.transitioningDelegate = self
    self.modalVC.modalPresentationStyle = .custom
    self.modalVC.modalPresentationCapturesStatusBarAppearance = true;
    self.present(self.modalVC!, animated: true, completion: nil)


    func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
        let containerView = transitionContext.containerView
        let fromViewController = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.from)
        let toViewController = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.to)
        toViewController!.view.transform = CGAffineTransform(scaleX: 0.001, y: 0.001)

        UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 0.8, initialSpringVelocity: 0.0, options: [.curveEaseOut], animations: { () -> Void in

            toViewController!.view.transform = CGAffineTransform.identity

        }, completion: { (completed) -> Void in

           transitionContext.completeTransition(completed)

        })
 }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I've been looking for a solution for 3 days. I don't like this solution but didn't found better way how to fix it.

I'he got situation when rootViewController view has bigger height for 20 points than window, when I've got notification about status bar height updates I manually setup correct value.

Add method to the AppDelegate.swift

func application(_ application: UIApplication, didChangeStatusBarFrame oldStatusBarFrame: CGRect) {
        if let window = application.keyWindow {
            window.rootViewController?.view.frame = window.frame
        }
    }

After that it works as expected (even after orientation changes). Hope it will help someone, because I spent too much time on this.

P.S. It blinks a little bit, but works.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...