1

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

Blane Townsend
  • 2,888
  • 5
  • 41
  • 55

2 Answers2

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

The complete tutorial found here !!!

Haris
  • 915
  • 1
  • 11
  • 28