Search code examples
iosxcodedraggablexib

How to enable the "draggable mode" on a customized item?


So here is my problem:

I've created a PostIt.xib (which is just composed with 2 labels and 2 textFields).

On my storyboard I've added a button and when I press it, it call his function addNewPostIt which... Add a new PostIt! :D

So, what I want to do now is to DragNDrop this PostIt... I really don't know how to process, so if someone could help me it would be very nice! Thanks a lot!

Here is my function: (x and y are static Integer which are auto incremented).

- (IBAction)addNewPostIt:(id)sender {

   PostIt *postit2 = [[[NSBundle mainBundle] loadNibNamed:@"PostIt" owner:self options:nil] firstObject];

   postit2.frame = CGRectMake(x, y, 400, 100);

   [self.view addSubview:postit2];

   x+=100;
   y+=100;

}

Solution

  • Use a UIGestureRecognizer, specifically a UIPanGestureRecognizer.