Search code examples
iphoneiosipadmove

How to allow a user to move a button via iOS sdk


I'm trying to do something new with my app.

I have a number of buttons that I'd like the user to be able to rearrange on the screen by dragging them. The view is currently created via Interface Builder. The ideal implementation would check for a flag in NSUserDefaults which if present would allow the user to move the object, drop it,then remove the flag which would save the setup for next time the user loads.

Anyone know if anything like this would be possible?


Solution

  • You can have it done by using the action method -

    //called on each instance during a drag event

    - (IBAction)draggedOut: (id)sender withEvent: (UIEvent *) event {
        UIButton *selected = (UIButton *)sender;
        selected.center = [[[event allTouches] anyObject] locationInView:self.view];
    }