Viv*_*ier 2 animation touch uiscrollview ios
我需要从UIScrollView获取触摸位置.但是当我为scrollview创建一个子类时:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
NSArray *touchesArray = [touches allObjects];
UITouch *touch = (UITouch *)[touchesArray objectAtIndex:0];
CGPoint point = [touch locationInView:self];
self.position = point;}
Run Code Online (Sandbox Code Playgroud)
该函数touchesBegan并不总是被调用.如果我快速滑动,touchesBegan从不调用,而是scrollViewDidScroll直接调用.
我无法使用,UIGesture (UITapGestureRecognizer, ... )因为用户不点按或滑动.
还有其他方法可以从UIScrollView获取位置吗?
编辑:
谢谢你:https://stackoverflow.com/a/15763450/1752843
UIScrollView子类:
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event{
self.position = point;
return self;
}
Run Code Online (Sandbox Code Playgroud)
要检测scrollview中的触摸位置,请尝试此代码
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTapGestureCaptured:)];
[scrollView addGestureRecognizer:singleTap];
- (void)singleTapGestureCaptured:(UITapGestureRecognizer *)gesture
{
CGPoint touchPoint=[gesture locationInView:scrollView];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6569 次 |
| 最近记录: |