ios – 视图控制器的交互式视图控制器从状态栏隐藏

前端之家收集整理的这篇文章主要介绍了ios – 视图控制器的交互式视图控制器从状态栏隐藏前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
这是我的 demo project.

我有两个视图控制器.主要的状态栏隐藏,第二个没有.

我创建了一个自定义驱动的转换动画,从控制器一到控制器二.

当我在子视图控制器(橙色)时,我通过从上到下平移开始驱动转换.您可以看到状态栏在拖动时回来.而UIButton“Hello”也在移动.

我取消了转换.然后我再次启动它,你可以看到状态栏也回来了,但这一次,我的按钮没有移动,它保持在同一个位置,好像状态栏仍然隐藏.

任何想法为什么一旦过渡被取消至少一次,它会表现如此?

(我甚至没有谈论动画的奇怪的事情,在取消时可能会翻倍(可能是模拟器的错误,因为它不会在我的iPhone 6 9.1和我的iphone 5 8.4上)

解决方法

添加:import Foundation

然后添加一个插座:

类ViewController:UIViewController {@H_404_23@@IBOutlet weak var topConstraint:NSLayoutConstraint!@H_404_23@…@H_404_23@}@H_404_23@@H_404_23@然后,当视图消失时,将值更改为0,然后将其显示为20:

override func viewWillAppear(animated: Bool) {
    topConstraint.constant = 20.0
}

override func viewWillDisappear(animated: Bool) {
    topConstraint.constant = 0.0
}

完整的代码(确保记住将限制连接到插座):

import UIKit
import Foundation

class ViewController: UIViewController {

    @IBOutlet weak var topConstraint: NSLayoutConstraint!
    let controllerTransition = InteractiveControllerTransition(gestureType: .Pan)
    let controllerTransitionDelegate = ViewController2Transition()

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view,typically from a nib.

        controllerTransition.delegate = controllerTransitionDelegate
        controllerTransition.edge = .Bottom


    }

    override func viewWillAppear(animated: Bool) {
        topConstraint.constant = 20.0
    }

    override func viewWillDisappear(animated: Bool) {
        topConstraint.constant = 0.0
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    @IBAction func unwindToViewController(sender: UIStoryboardSegue) { }

    override func prefeRSStatusBarHidden() -> Bool {
        return false
    }

    @IBAction func helloButtonAction(sender: UIButton) {
//      let storyBoard = UIStoryboard(name: "Main",bundle: nil)
//      let vc = storyBoard.instantiateViewControllerWithIdentifier("ViewController2") as! ViewController2
//      
//      vc.transitioningDelegate = controllerTransition
//      controllerTransition.toViewController = vc
//      
//      self.presentViewController(vc,animated: true,completion: nil)

        let storyBoard = UIStoryboard(name: "Main",bundle: nil)
//      let nvc = storyBoard.instantiateViewControllerWithIdentifier("NavigationViewController2") as! UINavigationController
//      let vc = nvc.topViewController as! ViewController2

        let vc = storyBoard.instantiateViewControllerWithIdentifier("ViewController2") as! ViewController2





//      nvc.transitioningDelegate = controllerTransition
        vc.transitioningDelegate = controllerTransition
        controllerTransition.toViewController = vc

//      self.presentViewController(nvc,completion: nil)
        self.presentViewController(vc,completion: nil)

    }

}

猜你在找的iOS相关文章