1

我刚刚完成了我的第一个应用程序。当我发现(10MB)内存泄漏时,我正要提交它。根据这篇文章,这是由我使用的 segues 引起的。

据我了解,目前我的应用程序每次执行 segue 时都会生成一个新视图。我一直在阅读很多帖子,最终让我感到困惑。我应该使用 dissmissViewController 吗?放松赛格?

这篇文章对 unwind segue 非常有帮助。但从 UI 的角度来看,我喜欢当前的 performSegueWithIdentifier 解决方案,因为我制作了不错的水平滑动转场。使用 unwind segue 时有没有办法自定义转换?

我希望有可能在自定义 segue 代码中简单地“杀死”以前的 ViewController ...

ps:这是segue之一的代码:

import UIKit

class FirstCustomSegueUnwind: UIStoryboardSegue {
override func perform() {
    var firstVCView = self.sourceViewController.view as UIView!
    var secondVCView = self.destinationViewController.view as UIView!


    let screenWidth = UIScreen.mainScreen().bounds.size.width
    let screenHeight = UIScreen.mainScreen().bounds.size.height

    secondVCView.frame = CGRectMake(-screenWidth, 0.0, screenWidth, screenHeight)

    let window = UIApplication.sharedApplication().keyWindow
    window?.insertSubview(secondVCView, aboveSubview: firstVCView)

    UIView.animateWithDuration(0.4, animations: { () -> Void in
        firstVCView.frame = CGRectOffset(firstVCView.frame, screenWidth, 0.0)
        secondVCView.frame = CGRectOffset(secondVCView.frame, screenWidth, 0.0)


        }) { (Finished) -> Void in
            self.sourceViewController.presentViewController(self.destinationViewController as! UIViewController, animated: false, completion: nil)

    }


}
}
4

0 回答 0