Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to make UIbutton draggable within UIView?

I need to drag and drop the button in my dash board i can drag and drop the button using the following code

- (void)viewDidLoad {
      [super viewDidLoad];
     [eventButton addTarget:self action:@selector(draggedOut:withEvent:)forControlEvents:UIControlEventTouchDragOutside |UIControlEventTouchDragInside];
  }

- (void) draggedOut: (UIControl *) c withEvent: (UIEvent *) ev {
       CGPoint point = [[[ev allTouches] anyObject] locationInView:self.view];
    if(point.y > 22 && point.y <300)
            c.center = CGPointMake(237, point.y - c.bounds.size.height/2 -5);
  }

but i need while drag and drop i need to change the positions of the buttons too

note:i wrote the code only for one button

please help me for my question

like image 363
Sri Avatar asked Oct 13 '22 19:10

Sri


1 Answers

- (void)viewDidLoad {
  [super viewDidLoad];
  [eventButton addTarget:self action:@selector(dragOut:withEvent:)forControlEvents:UIControlEventTouchDragOutside |UIControlEventTouchDragInside];
   }

-(IBAction)dragOut: (id)sender withEvent: (UIEvent *) event {
 UIButton *selected = (UIButton *)sender;
 selected.center = [[[event allTouches] anyObject] locationInView:self.view];
 }
like image 91
Steve Avatar answered Nov 01 '22 11:11

Steve