这是我的demo project。
我有两个视图控制器。主要的状态栏隐藏,而第二个没有。
我创建了一个自定义驱动的过渡动画,从控制器1转到控制器2。
当我在子视图控制器(橙色视图)上时,我通过从上到下平移来启动驱动过渡。拖动时,您可以看到状态栏正在返回。而UIButton
"你好"也在移动。
我取消了过渡。然后我再次启动它,你可以看到状态栏也回来了,但这一次,我的按钮没有移动,它停留在同一个位置,好像状态栏仍然是隐藏的。
知道为什么一旦转换至少被取消一次就会出现这样的行为?
(我甚至没有谈论动画的奇怪之处,取消时会加倍(可能是模拟器的一个错误,因为它不会在我的iphone 6 9.1和我的iphone上做到这一点) 5 8.4。)
答案 0 :(得分:4)
添加:import Foundation
然后添加一个插座:
class ViewController: UIViewController {
@IBOutlet weak var topConstraint: NSLayoutConstraint!
...
}
然后在视图消失时将值更改为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, animated: true, completion: nil)
self.presentViewController(vc, animated: true, completion: nil)
}
}