Recognize which control touched
Imagine that i put several controls o开发者_Python百科n view how can i recognize which control touched ?
I use below code but doesn't work
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
if([touch view]==btn)
//...
}
I'd use a UIPanGestureRecognizer.
Instantiate one and hook it to each view you want to have be draggable. Then when it fires, use its translationInView:
method to get the translation to apply to the view itself.
See here for the docs on UIPanGestureRecognizer: http://developer.apple.com/library/ios/#documentation/uikit/reference/UIPanGestureRecognizer_Class/Reference/Reference.html#//apple_ref/occ/cl/UIPanGestureRecognizer
精彩评论