Swift - 自定义 Segue 错误('view' 的使用不明确)

Swift - Custom Segue Error (Ambiguous use of 'view')

我正在尝试制作自定义 segue,它一直告诉我我正在使用 'view' 的模糊用法。谁能解释一下这是怎么回事?

Code:

import UIKit

class customSegue: UIStoryboardSegue {

    override func perform() {

        let sourceVC: AnyObject = self.sourceViewController
        let destinationVC: AnyObject = self.destinationViewController

        sourceVC.view.addSubview(destinationVC.view)

        destinationVC.view.transform = CGAffineTransformMakeScale(0.05, 0.05)

        UIView.animateWithDuration(0.5, delay: 0.0, options: .CurveEaseInOut, animations: { () -> Void in

            destinationVC.view.transform = CGAffineTransformMakeScale(1.0, 1.0)

            }) { (finished) -> Void in

                destinationVC.view.removeFromSuperview()

                let time = dispatch_time(DISPATCH_TIME_NOW, Int64(0.001 * Double(NSEC_PER_SEC)))

                dispatch_after(time, dispatch_get_main_queue()) {

                    sourceVC.presentViewController(destinationVC, animated: false, completion: nil)

            }
        }
    }
}

The 3 Lines of code that give error - Ambiguous use of 'view' :

sourceVC.view.addSubview(destinationVC.view)

destinationVC.view.transform = CGAffineTransformMakeScale(0.05, 0.05)

destinationVC.view.transform = CGAffineTransformMakeScale(1.0, 1.0)

您收到这些错误的原因是您将 sourceVCdestinationVC 变量输入为 AnyObject。您必须将变量键入 UIViewController,这样 swift 才能看到正确的 view 属性。您的变量声明将如下所示:

let sourceVC: UIViewController = self.sourceViewController
let destinationVC: UIViewController = self.destinationViewController