I have four UIButtons in my interface file. I have outlets attached to each button. I want to be able to drag and drop them across the screen. What is the best way to do this? How can I do this? please help!!!
Asked
Active
Viewed 1,909 times
1
-
Hover the mouse over the button, hold down the mouse button, and move the mouse. – PengOne Jun 17 '11 at 22:10
-
2I think he meant from within the app. – Jonathan. Jun 18 '11 at 00:02
-
Apple's [Touches sample app](http://developer.apple.com/library/ios/ipad/#samplecode/Touches/Introduction/Intro.html) may help you. – Jun 18 '11 at 01:47
2 Answers
1
try this u can drag and drop your button what ever you want
implement this code in ViewDidLoad
[self.shoeimageOutlet addTarget:self action:@selector(imageMoved:withEvent:) forControlEvents:UIControlEventTouchDragInside];
[self.shoeimageOutlet addTarget:self action:@selector(imageMoved:withEvent:) forControlEvents:UIControlEventTouchDragOutside];
it will call the method written below
- (IBAction) imageMoved:(id) sender withEvent:(UIEvent *) event
{
CGPoint point = [[[event allTouches] anyObject] locationInView:self.view];
UIControl *control = sender;
control.center = point;
}

SARATH SASI
- 1,395
- 1
- 15
- 39
0
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

Haris
- 915
- 1
- 11
- 28