简体   繁体   中英

How to detect the touch (CGPoint) of a scroll view in its content size in iPhone?

I want to detect the touch (CGPoint) of a scroll view in its content size. If I detect the touch in the scroll I get the CGPoint only with reference to the scroll view frame, but I want the position with reference to content size.

Here is my code

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch* t;
NSLog(@"inside touches began");
if([[event allTouches] count]==1){
    t=[[[event allTouches] allObjects] objectAtIndex:0];
    p1=[t locationInView:scroll];
}

My scroll view frame is (0,0,320,460) and content size is (320,800);

If I scroll my view and touch it at bottom, the CGPoint value obtained is 450 but I want to get as 750 (with reference to content size).

I think what you want is

CGPoint touchInScrollView = [theUITouch locationInView:theScrollView];

If I'm reading my code right. :)

也许您可以使用UIScrollViewcontentOffset来计算正确的点?

CGPoint realPoint = CGPointMake( scrollView.contentOffset.x + p1.x, scrollView.contentOffset.y + p1.y );

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