TextField Draggable in Swift iOS -


i want drag textfield around view. im having small problem code.

here code

   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     } 

problem if tried touch on textfield , drag doesn't work. if touch somewhere else , drag finger textfield start drag. want t make if touch on textfiel.

you can achieve adding gesture text field:

override func viewdidload() {     super.viewdidload()       var gesture = uipangesturerecognizer(target: self, action: selector("userdragged:"))     bottomtextfield.addgesturerecognizer(gesture)     bottomtextfield.userinteractionenabled = true }  func userdragged(gesture: uipangesturerecognizer){     var loc = gesture.locationinview(self.view)     self.bottomtextfield.center = loc  } 

Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -