在我的项目中我有主视图控制器,我更换其内容取决于App Logic
所以这个主视图控制器将有不同的内容,我通过这段代码做到了:
var contentViewController: UIViewController! {
didSet {
// remove any previous views
for view in self.contentView.subviews {
view.removeFromSuperview()
}
// add the view
// the ViewController must be aded to the children list to avoid being released (as it become a Zombie)
self.addChildViewController(self.contentViewController)
if registerDoneFlag {
//do some animation
let animation = CATransition()
animation.duration = 0.3
animation.type = kCATransitionPush
animation.subtype = kCATransitionFromTop
animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
self.contentView.layer.addAnimation(animation, forKey: "SwitchToView1")
registerDoneFlag = false
}
if backFlag {
//do some animation
let animation = CATransition()
animation.duration = 0.3
animation.type = kCATransitionPush
animation.subtype = kCATransitionFromBottom
animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
self.contentView.layer.addAnimation(animation, forKey: "SwitchToView1")
backFlag = false
}
self.contentView.addSubview(self.contentViewController.view)
self.contentViewController.didMoveToParentViewController(self)
}
}
在某些情况下,内容从未改变过,虽然我调试项目时执行了上一个代码,但布局从未改变,即应用程序似乎永远渲染 UI 。
所以当这个案例发生时,我的应用程序冻结在最后一个VC中,我无法导航到应用程序,直到我杀死该应用程序。
有没有人遇到这样的问题?
请帮助,
感谢。