开发者

how to detect number of touches on the uiview in iphone sdk

开发者 https://www.devze.com 2023-04-10 05:05 出处:网络
in my app, when the user touches on the view ,i am showing an UIImageView there and i drag and drop the image from another UIImageView to that touched UIImageView.

in my app, when the user touches on the view ,i am showing an UIImageView there and i drag and

drop the image from another UIImageView to that touched UIImageView.

But the problem is that, only the recent touched UIImageView is activated. i mean ,when i

click 3 times then shows 3 UIImageViews but only the last is activated and accept the another

image.

How can i make all touched UIImageViews are activated .. Any开发者_StackOverflow body help on this..

Thanks in advance.


You should read Apples documentation on the responder chain and event handling. The key UIView method here is

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event 

This method traverses the view hierarchy by sending the pointInside:withEvent: message to each subview to determine which subview should receive a touch event. If pointInside:withEvent: returns YES, then the subview’s hierarchy is traversed; otherwise, its branch of the view hierarchy is ignored. You rarely need to call this method yourself, but you might override it to hide touch events from subviews.


You should try this: Where there is your UIView (Or a view):

UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapped:)];
tapGesture.numberOfTapsRequired = 1;//number of tap
[view addGestureRecognizer:tapGesture];

The selector:

-(void)tapped:(UITapGestureRecognizer *)sender {
NSLog(@"Pressed");
}
0

精彩评论

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