I Want to add drag & drop functionality on UIButton. Actually I have created numbers of buttons programmatically under UIScrollView. I add following target on UIButton
[mybutton addTarget:self action:@selector(wasDragged:withEvent:)forControlEvents:UIControlEventTouchDragInside];
and this is the method
- (void)wasDragged:(UIButton *)button withEvent:(UIEvent *)event
{
// get the touch
UIButton *myButton=[[UIButton alloc]init];
myButton=button;
[self.scrollView addSubview:myButton];
UITouch *touch = [[event touchesForView:button] anyObject];
//get delta
CGPoint previousLocation = [touch previousLocationInView:myButton];
CGPoint location = [touch locationInView:myButton];
CGFloat delta_x = location.x - previousLocation.x;
CGFloat delta_y = location.y - previousLocation.y;
//move button
myButton.center = CGPointMake(myButton.center.x + delta_x,myButton.center.y + delta_y);
}
This code is working fine under the scroll view and button is drag & drop inside the scrollview. Now problem is when I drag the button outside the scrollview, button disappear.
I want to drag button outside the scrollview also. How can I do this?
How can I drag button from Scrollview to another UIView? How is it possible?
I solved this problem by changing code
to