Swift 方法与超类中的方法冲突-重写产生错误
我得到了Swift 方法与超类中的方法冲突-重写产生错误,swift,sprite-kit,Swift,Sprite Kit,我得到了类菜单:SKScene,然后它里面有一个func touches开始,这给了我以下错误: 使用Objective-C选择器的方法“touchesBegind(:withEvent:)”来自具有相同Objective-C选择器的超类“UIResponder”的方法“touchesBegind:withEvent:)”与方法“touchesBegind(:withEvent:)”冲突 无论如何,如果我在函数前面添加覆盖,它会说: 方法不重写其超类中的任何方法 有什么想法吗?整个代码: imp
类菜单:SKScene
,然后它里面有一个func touches开始
,这给了我以下错误:
使用Objective-C选择器的方法“touchesBegind(:withEvent:)”来自具有相同Objective-C选择器的超类“UIResponder”的方法“touchesBegind:withEvent:)”与方法“touchesBegind(:withEvent:)”冲突
无论如何,如果我在函数前面添加覆盖,它会说:
方法不重写其超类中的任何方法
有什么想法吗?整个代码:
import SpriteKit
class Menu: SKScene {
var title : SKLabelNode?
var start : SKLabelNode?
override func didMoveToView(view: SKView) {
backgroundColor = SKColor.whiteColor()
self.title = SKLabelNode(fontNamed: "Chalkduster")
self.start = SKLabelNode(fontNamed: "Chalkduster")
self.title!.name = "title"
self.start!.name = "new"
self.addChild(self.title!)
self.addChild(self.start!)
}
func touchesBegan(touches: NSSet, withEvent even: UIEvent) {
self.menuHelper(touches)
}
func menuHelper(touches: NSSet) {
for touch in touches {
let nodeAtTouch = self.nodeAtPoint(touch.locationInNode(self))
if nodeAtTouch.name == "title" {
print("Title pressed")
}
else if nodeAtTouch.name == "new" {
print("Start pressed")
}
}
}
此方法的签名(来自文档)为
func touchesBegan(_ touches: Set<UITouch>, withEvent event: UIEvent?)
非常感谢你!仍在学习基础知识。
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
self.menuHelper(touches)
}