swift - 方法不会覆盖其父类(super class)中的任何方法

标签 swift touchesbegan touchesmoved

当我遇到这个错误时,我正在尝试创建一个新的覆盖函数:方法不会覆盖它的父类(super class)中的任何方法

我已经尝试删除覆盖部分,但这只会给我另一个错误。

override func touchesBegan(touches: NSSet!, withEvent event: UIEvent!) {

    let touch : UITouch! = touches.anyObject() as! UITouch

    location = touch.locationInView(self.view)

    person.center = location
}

override func touchesMoved(touches: NSSet!, withEvent event: UIEvent!) {

    let touch : UITouch! = touches.anyObject() as! UITouch

    location = touch.locationInView(self.view)

    person.center = location

}

最佳答案

正确的方法签名是:

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {

}

override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) {

}

关于swift - 方法不会覆盖其父类(super class)中的任何方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33466391/

相关文章:

swift - Firebase 结合查询和分页

如果滑动,Swift 不会触发 touchesBegan

ios - 无法在 iOS 的 viewController 中调用 touchesBegan/touchesMoved 方法

swift - 如何暂停touchesBegan并仅使用touchesMoved,反之亦然?

ios - 快速触摸开始并将其显示在触摸的对象上

ios - Swift:如何从其他 View 更改 View 的背景

ios - 循环视频 KUDAN AR

ios - iPhone 中的 bing map 集成

objective-c - 在 UIView 而非 UIImageView 上自由手绘

xcode - SQlite数据库SELECT EXC_BAD_INSTRUCTION代码EXC_I386_INVOP子代码0x0