luckysmiles asks:
Pls anyone help me…how to move controls(like button,label.. ) from one place to another using touch events in iphone..
There are 3 possibilities nowadays on how to enable items – that is UIViews and UIControls – to be draggable.
- override touchesMoved
- add a target/selector for dragging control events
- add a pan gesture recognizer
All those are variations on essentially the same thing: the iOS delivers touches to your app and you have more or less intelligent plumbing to calculate a moving vector. Then you apply this delta to either the frame of the thing to be moved or, more intelligently change the item’s center property.
When I started building a sample I wanted to create a UIButton subclass with the added draggability and have this button be instantiated from a XIB. Now it turns out that you can only create custom buttons like this, not rounded rect buttons like you usually do. The reason for this being that the regular initWithFrame or initWithCoder for a subclassed UIButton would need to instead create a UIRoundedRectButton (private Apple class) to look like that.
Read more