5

While my user is dragging his finger while holding down a UIButton, can I get the touch location for the finger at that point? If I can't do this it seems that I could probably create a UIImageView and give it button qualities. After this I would implement the touches began, moved, ended methods.

These methods; however, do not run while a UIButton has been touched.

The reason I need this is because I wanted to find out the direction of a touch drag outside movement, and for various other reasons too, but if this is impossible I will have to create UIImageViews I think.

Also, I do not subclass UIButton, I am too much beginner to take on apples clusters.

1
  • You may just want to add a gesture recogniser for this.
    – hypercrypt
    Commented Aug 11, 2012 at 4:30

1 Answer 1

19

you should following this:

[myButton addTarget:self action:@selector(dragHandler:withEvent:) forControlEvents:UIControlEventTouchDragInside];
[myButton addTarget:self action:@selector(dragHandler:withEvent:) forControlEvents:UIControlEventTouchDragOutside];

-(void)dragHandler:(UIButton *)sender withEvent:(UIEvent *)event
{
    UITouch *touch = [[event allTouches] anyObject];

    NSLog(@"touchInfo:%@", NSStringFromCGPoint([touch locationInView:self.view]);
}
1
  • wish i could thumb you up but only have a 1 rep
    – bmende
    Commented Aug 11, 2012 at 4:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.