开发者

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜