动画scheduledTimer错误

时间:2017-01-08 08:03:59

标签: ios swift swift3

继续说在代码中找不到方法endBlink的错误。任何人都可以帮我解决它吗?我认为是swift 3的新语法风格的选择器参数问题

private func endBlink(timer : Timer){

    // some action to do
}

private func startBlink(){

        faceView.eyeOpen = false
        // wait a section then open eyes 
        Timer.scheduledTimer(timeInterval: 2.0,
                             target:  self,
                             selector:self.endBlink(_:),
                             userInfo: nil,
                             repeats: false)

}

2 个答案:

答案 0 :(得分:0)

@objc
func endBlink() {

}

private func startBlink(){

    faceView.eyeOpen = false
    // wait a section then open eyes 
    Timer.scheduledTimer(timeInterval: 2.0,
                         target:  self,
                         selector:#selector(endBlink),
                         userInfo: nil,
                         repeats: false)

}

答案 1 :(得分:0)

删除第一个方法的“private”,并应用“#selector”:

func endBlink(timer:Timer){
        // some action to do
}


private func startBlink(){
        faceView.eyeOpen = false
        // wait a section then open eyes
        Timer.scheduledTimer(timeInterval: 2.0,
                             target:  self,
                             selector:#selector(endBlink),
                             userInfo: nil,
                             repeats: false)

}