当我的应用程序启动时,我有一个加载视图控制器,当此视图控制器中的动画完成时,我希望它显示另一个视图控制器并使用动画关闭视图控制器。
加载视图控制器是初始视图控制器,
我在UIStoryboard.mflMainTabBarViewController()时有这段代码。返回我想要呈现的视图控制器
func animationDidStop(_ anim: CAAnimation, finished flag: Bool) {
let animationID = anim.value(forKey: "animationID")
if animationID as! NSString == "transform" {
self.present(UIStoryboard.mflMainTabBarViewController(), animated: true, completion: {
_ = self.popoverPresentationController
})
}
}`
但是当deinit从未被召唤时
deinit {
print("deinit")
}
取消第一个视图控制器,并使呈现视图控制器成为根视图控制器的最佳方法是什么?
答案 0 :(得分:0)
当您使用弱引用周期时deinit
方法正在调用。在强引用周期deinit
中没有调用。因此,为调用方法创建弱引用循环。
另请参阅this link.
答案 1 :(得分:0)
试试这个。
使用vc的父级来呈现。
并解雇vc本身。
self.presentingViewController?.present(UIStoryboard.mflMainTabBarViewController(), animated: true, completion: {
_ = self.popoverPresentationController
})
self.dismiss(animated: false, completion: nil)
或
self.navigationController?.present(UIStoryboard.mflMainTabBarViewController(), animated: true, completion: {
_ = self.popoverPresentationController
})
self.navigationController?.popViewController(animated: false)
答案 2 :(得分:0)
如果您100%确定自我永远不会是零,那么只需使用
func animationDidStop(_ anim: CAAnimation, finished flag: Bool) {
let animationID = anim.value(forKey: "animationID")
if animationID as! NSString == "transform" {
self.present(UIStoryboard.mflMainTabBarViewController(), animated: true, completion: { [unowned self] in
_ = self.popoverPresentationController
})
}
}`
weak
和unowned
是相同的。除了一件事。与我们看到的weak
不同,unowned
不会在闭包块中自动将self
转换为可选项。