我的屏幕上有图像视图,我想要检测,当用户从左到右和从右到左不停止滑动此图像时。当他这样做时,他的手指仍然在屏幕上。我想要的每次滑动都添加到我的swipeCount
变量中。
我试过这个:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
self.startPosition = [touch locationInView:self.imageView];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint endPosition = [touch locationInView:self.imageView];
if (self.startPosition.x != endPosition.x || self.startPosition.y != endPosition.y) {
self.swipeCount++;
self.labelSwipeCount.text = [NSString stringWithFormat:@"%d", self.swipeCount];
}
}
但是如果用户没有超出图像范围,那么touchesEnded不起作用。我怎样才能实现自己的想法?