我的代码:

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
                            }
                                             }
                          }
        }

关于ios - “touchesBegan”错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32737965/

10-09 03:24