触摸开始/移动/结束不适用于 xcode 6.3
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29552897/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
touchesbegan/moved/ended not working with xcode 6.3
提问by user3302800
I'm having the same problem as listed with the beta 6.3 here: Overriding method with selector 'touchesBegan:withEvent:' has incompatible type '(NSSet, UIEvent) -> ()'
我遇到了与此处列出的 beta 6.3 相同的问题:使用选择器 'touchesBegan:withEvent:' 的覆盖方法具有不兼容的类型 '(NSSet, UIEvent) -> ()'
but the fixes listed there are not working for me. I've changed this line:
但是那里列出的修复程序对我不起作用。我改变了这一行:
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
to this:
对此:
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
The error I'm getting is: "Method does not override any method from its superclass"
我得到的错误是:“方法不会覆盖其超类中的任何方法”
Does anyone know if the fixes listed above for the 6.3 beta are really working with the final 6.3?
有谁知道上面列出的 6.3 测试版修复程序是否真的适用于最终的 6.3?
回答by Oliver Shaw
回答by user3302800
So I found the answer to my own question ... this was caused by a class I had already defined in my project called "Set". (that was from a tutorial from Ray W about making a candy crush game). Anyway, in Swift 1.2 they introduced their own class called "Set" and it was causing name collision problems. So I just renamed the old Set class and it all started working. UGH!
所以我找到了我自己问题的答案......这是由我在我的项目中定义的一个名为“Set”的类引起的。(这是来自 Ray W 关于制作糖果粉碎游戏的教程)。无论如何,在 Swift 1.2 中,他们引入了自己的名为“Set”的类,这导致了名称冲突问题。所以我只是重命名了旧的 Set 类,它就开始工作了。啊!
回答by poojathorat
Here is the complete code for touchesBegan there is also change in accessing UITouch object.
这是 touchesBegan 的完整代码,访问 UITouch 对象也有变化。
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
super.touchesBegan(touches, withEvent: event);
mouseSwiped = false
let array = Array(touches)
let touch = array[0] as! UITouch
currentLocation = touch.locationInView(imgViewSignature)
currentLocation.y += 0
}
回答by A.G
Here is my simple code.
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
super.touchesBegan(touches, withEvent: event);
usernameTF.resignFirstResponder()
passwordTF.resignFirstResponder()
self.view.endEditing(true)
}