我的代码:
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
如何解决?
答案 0 :(得分:0)
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
}
}
}
}
答案 1 :(得分:0)
试试这个
if let touch = touches.first as? UITouch
{
}