Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to get the location of a users touch while pressing UIButton?

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.

like image 921
bmende Avatar asked Aug 11 '12 04:08

bmende


1 Answers

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]);
}
like image 161
bitmapdata.com Avatar answered Sep 20 '22 21:09

bitmapdata.com