开发者

How can I get touch position in scrollViewDidScroll method?

I try to get touch position when I scroll the screen. I try to get it from touchBegin() but I can't. That开发者_运维问答's because touchBegin never called during scroll. How can I solve this problem??? Quickly Answer to me.


using the scrollview gesture recognizer :

-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    CGPoint positionInView = [scrollView.panGestureRecognizer locationInView:myView];
}


I found my self it solution.

First, I set the scrollView.contentSize to scrollView.frame. so it can't call scrollViewDidScroll

- (id)initWithFrame:(CGRect)frame
{
    ....
    self.frame = frame
    self.contentSize = frame;
    ....
}

Second, when touchesBegan set the scrollView.contentSize what I want. then the event will go to scrollViewDidScroll. You can act something.

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
      ....
    self.contentSize = myView.frame.size;
      ....
}

Thrid, in scrollViewDidEndDecelerating set the contentSize and save the contentOffest;

-(void) scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    CGPoint pointTemp = self.contentOffset;
    self.contentSize = self.frame.size;
    self.contentOffset = pointTemp;
}

This will be pathetic way. If you know other, please teach me

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜