Ios 代码从swift 2.0迁移到swift 3.0后出错

Ios 代码从swift 2.0迁移到swift 3.0后出错,ios,swift,swift3,migration,Ios,Swift,Swift3,Migration,任何人都可以帮助我解决这个错误,只要看看下面的代码 override func viewDidLoad() { super.viewDidLoad() ... ... //the following line occurs error: "Ambiguous use of 'startAnimation'" **perform(#selector(UIViewAnimating.startAnimation), with: nil, afterDelay: 0.3)** }

任何人都可以帮助我解决这个错误,只要看看下面的代码

override func viewDidLoad() {
  super.viewDidLoad()
  ...
  ...

  //the following line occurs error: "Ambiguous use of 'startAnimation'"
  **perform(#selector(UIViewAnimating.startAnimation), with: nil, afterDelay: 0.3)**
}
如何解决上述问题?

使用
UIView
类方法

+(void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations



   UIView.animate(withDuration:duration){    
            // code to be executed    
     }

查看此UIView方法文档和类似查询

UIViewAnimating
已经有一种方法可以在延迟后启动动画,您应该改用此方法:

startAnimation(afterDelay: 0.3)
如果您坚持使用
perform(u:with:afterDelay:)
您可以这样使用它:

perform(NSSelectorFromString("startAnimation"), with: nil, with: 0.3)
但请记住,这种方法会降低编译器的安全性,如果在选择器中输入错误,应用程序将崩溃

另外,您的代码很奇怪,因为
UIViewController
不符合
uiviewmanimating
,因此除非您自己实现该协议(这很不寻常),否则它将无法工作。更有可能的情况是,您的视图控制器中有一个名为
startAnimation
的方法,并且Swift migrator错误地将引用添加到
UIViewAnimating
。在这种情况下,正确的代码为:

perform(#selector(self.startAnimation), with: nil, afterDelay: 0.3)

迁移到Swift 3.0之前的代码是什么?为什么要这样调用该方法?为什么不通过
perform()
?查看有关问题的解释。谢谢大家!我真的很感谢你的帮助~谢谢你的帮助,但是第一行似乎有点复杂,我会研究你稍后回复的内容~@K.Zeng请查看这些链接。