views:

67

answers:

2

Hi,

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).Please help me out.Thanks.

A: 

Maybe you can use the contentOffset of the UIScrollView to calculate the correct point?

CGPoint realPoint = CGPointMake( scrollView.contentOffset.x + p1.x, scrollView.contentOffset.y + p1.y );
aegzorz
+1  A: 

I think what you want is

CGPoint touchInScrollView = [theUITouch locationInView:theScrollView];

If I'm reading my code right. :)

Kalle