我希望能够在视图中拖动文本框,但我的代码有些小问题。
以下是我的代码:
问题是如果我试图触摸文本字段并拖动,它就不起作用。但如果我只是在其他地方触摸并拖动手指,那么文本字段开始拖动。我希望只有当我触摸到那个文本字段时才能拖动它。
以下是我的代码:
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
var touch : UITouch! = touches.first as! UITouch
location = touch.locationInView(self.view)
bottomTextField.center = location
}
override func touchesMoved(touches: Set<NSObject>, withEvent event: UIEvent) {
var touch : UITouch! = touches.first as! UITouch
location = touch.locationInView(self.view)
bottomTextField.center = location
}
问题是如果我试图触摸文本字段并拖动,它就不起作用。但如果我只是在其他地方触摸并拖动手指,那么文本字段开始拖动。我希望只有当我触摸到那个文本字段时才能拖动它。