Swift 3.0

时间:2016-09-21 10:12:27

标签: ios swift swift3

我遇到了这段代码的问题:

private static func replaceAnimationMethods() {
        //replace actionForLayer...
        method_exchangeImplementations(
            class_getInstanceMethod(self, #selector(UIView.actionForLayer(_:forKey:))),
            class_getInstanceMethod(self, #selector(UIView.EA_actionForLayer(_:forKey:))))

        //replace animateWithDuration...
        method_exchangeImplementations(
            class_getClassMethod(self, #selector(UIView.animateWithDuration(_:animations:))),
            class_getClassMethod(self, #selector(UIView.EA_animateWithDuration(_:animations:))))
        method_exchangeImplementations(
            class_getClassMethod(self, #selector(UIView.animateWithDuration(_:animations:completion:))),
            class_getClassMethod(self, #selector(UIView.EA_animateWithDuration(_:animations:completion:))))
        method_exchangeImplementations(
            class_getClassMethod(self, #selector(UIView.animateWithDuration(_:delay:options:animations:completion:))),
            class_getClassMethod(self, #selector(UIView.EA_animateWithDuration(_:delay:options:animations:completion:))))
        method_exchangeImplementations(
            class_getClassMethod(self, #selector(UIView.animateWithDuration(_:delay:usingSpringWithDamping:initialSpringVelocity:options:animations:completion:))),
            class_getClassMethod(self, #selector(UIView.EA_animateWithDuration(_:delay:usingSpringWithDamping:initialSpringVelocity:options:animations:completion:))))

    }

我正在尝试迁移到Swift 3.0。

有关:

class_getClassMethod(self, #selector(UIView.animate(withDuration:animations:)(_:animations:))),

我收到错误Expected expression in list of expressions

有关:

class_getClassMethod(self, #selector(UIView.animate(withDuration:animations:completion:)(_:animations:completion:))),

我收到错误Expected ',' separator

坚持想法如何解决这个问题。任何指针都会非常感激。

1 个答案:

答案 0 :(得分:0)

您是否尝试过以下语法。

class_getClassMethod(self, #selector(UIView.animate(withDuration:animations:)))
class_getClassMethod(self, #selector(UIView.animate(withDuration:animations:completion:)))