简体   繁体   English

如何在iPhone的内容大小中检测滚动视图的触摸(CGPoint)?

[英]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. 我想检测滚动视图的内容大小(CGPoint)。 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. 如果我在滚动中检测到触摸,则仅参照滚动视图框架获得CGPoint,但是我希望根据内容大小确定位置。

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); 我的滚动视图框架是(0,0,320,460),内容大小是(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). 如果我滚动视图并在底部触摸它,则获得的CGPoint值为450,但我希望为750(参考内容大小)。

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 );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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