简体   繁体   中英

iOS: Touch Event in UIScroll view

I have tried so many thing to get touch inside a UIScrollView but I'm not getting how to do it.

Actually I want to touch inside a UIScrollView and get the location of subview (which i have touched).

You can do it with gesture recognizers. For detect single tap location use UITapGestureRecognizer

UITapGestureRecognizer *tapRecognizer = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)] autorelease];
[myScrollView addGestureRecognizer:tapRecognizer];

- (void)tapAction:(UITapGestureRecognizer*)sender{ 
    CGPoint tapPoint = [sender locationInView:myScrollView];
    CGPoint tapPointInView = [myScrollView convertPoint:tapPoint toView:self.view];
}

To convert that tapPoint to self.view you can use convertPoint:toView: method in UIView class

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM