"touchesBegan" 错误
Error with "touchesBegan"
我的代码:
var location = CGPoint(x:0,y:0)
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
let touch = touches.anyObject() as? UITouch
location = touch.locationInView(self.view)
Button.center = location
}
这一行报错:
let touch = touches.anyObject() as? UITouch
如何解决?
Try this : -
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
for touch in touches {
if let touch = touches.first as? UITouch {
if touch.tapCount == 2{
//Do Something here
}
}
}
}
试试这个
if let touch = touches.first as? UITouch
{
}
我的代码:
var location = CGPoint(x:0,y:0)
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
let touch = touches.anyObject() as? UITouch
location = touch.locationInView(self.view)
Button.center = location
}
这一行报错:
let touch = touches.anyObject() as? UITouch
如何解决?
Try this : -
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
for touch in touches {
if let touch = touches.first as? UITouch {
if touch.tapCount == 2{
//Do Something here
}
}
}
}
试试这个
if let touch = touches.first as? UITouch
{
}