2017-08-09 84 views
0

我有一个加载视图控制器,当我的应用程序启动时,当这个视图控制器中的动画完成时我希望它显示另一个视图控制器并关闭视图控制器的动画。决定加载视图控制器的最佳方法是什么?

装载视图控制器是初始视图控制器,

我有此代码时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") 
} 

什么是DEINIT第一视图控制器的最佳方式,并使得呈现视图控制器根视图控制器?

回答

0

当您在使用弱参考周期时deinit方法正在调用。在强参考周期deinit不能拨打。因此创建调用该方法的弱引用周期。

另请参阅this link.

+0

即使当我添加弱变弱weakSelf = self _ = weakSelf?.popoverPresentationController deinit不需要调用 – dmram

+0

你能告诉我你的代码吗? – shahnilay86

+0

其相同,我只是取代了自我。与weakSelf当做popover – dmram

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) 
+0

由于某种原因,navigationController是零,你有什么想法正在进行? – dmram

+0

@dmram也许你不使用push? – KANGKANG

+0

我不是,我的第一个视图控制器(加载视图控制器)是初始视图控制器 – dmram

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 
      }) 

     } 
}` 

weakunowned是相同的。除了一件事。与weak不同,我们已经看到,unowned不会自动将self转换为闭包区块中的可选项。

相关问题