【发布时间】:2015-09-29 01:47:26
【问题描述】:
我收到了这个 Swift 错误:
方法不会覆盖其超类中的任何方法!
为什么会出现这个?相关代码如下:
class TouchyView: UIView {
override func touchesBegan(touches: NSSet?, withEvent event: UIEvent) {
updateTouches(event.allTouches())
}
override func touchesMoved(touches: NSSet?, withEvent event: UIEvent) {
updateTouches(event.allTouches())
}
override func touchesEnded(touches: NSSet?, withEvent event: UIEvent) {
updateTouches(event.allTouches())
}
override func touchesCancelled(touches: NSSet!!, withEvent event: UIEvent) {
updateTouches(event.allTouches())
}
var touchPoints = [CGPoint]()
func updateTouches( touches: NSSet? ) {
touchPoints = []
touches?.enumerateObjectsUsingBlock() { (element,stop) in
if let touch = element as? UITouch {
switch touch.phase {
case .Began, .Moved, .Stationary:
self.touchPoints.append(touch.locationInView(self))
default:
break
}
}
}
setNeedsDisplay()
}
【问题讨论】:
-
我不明白,我看过那个帖子并尝试了那个解决方案,但它不适用于我的代码:(
-
你试过这个吗? stackoverflow.com/a/30892467/1749822 -- 围绕同一主题有很多问题。
-
我找到了解决办法!
标签: swift overriding