我的问题很奇怪但很简单。 我将我的客户 UIScrollView 子类化:MyScrollView,其中我禁用了滚动:
self.scrollEnabled = NO;
这意味着除了
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
所有其他 UIScrollViewDelegate 方法都不会被调用 在MyScrollView中,我通过检测屏幕上的用户触摸移动来进行内容滚动,也就是说没有翻转,没有弹跳,我的实现是在touchesMoved:withEvent:方法中
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
// NSLog(@"touch.phase:%d",touch.phase);
CGPoint currentPosition = [touch locationInView:self];
CGPoint lastTouchPosition = [touch previousLocationInView:self];
CGFloat deltaY = lastTouchPosition.y - currentPosition.y;
CGFloat contentYOffset = self.contentOffset.y + deltaY;
[self setContentOffset:CGPointMake(0,contentYOffset) animated:NO];
}
用户拖动移动完成后,我根据touchesEnded:withEvent中MyScrollView的内容偏移量执行自己的方法:
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
//some implementation according to current content offset
}
用户在屏幕上移动手指,每当手指离开屏幕表面时,touchesEnded:withEvent:就会被调用,我可以正确实现自己的方法。
但是,当用户将手指在屏幕表面上从屏幕内部移动到屏幕外部(顶部或底部),然后抬起手指时,touchesEnded:withEvent: 方法从未被调用,似乎 ios 不处理移出边界(顶部或底部)事件作为触摸结束事件,当触摸超出屏幕边界时,iOS 也不知道发生了什么
有人可能建议我检测 TouchMoved:withEvent: 中的当前位置,以检查它是否在界内。当运动非常慢时,这可能有效,但是当运动非常快时,系统无法检测到每个点的位置,看起来像是在一定的时间间隔内检测到运动。 任何人都可以帮我解决如何检测用户手指是否移出界限
最佳答案
我认为 touchesCancelled:withEvent:
方法将被调用!
关于iphone - 触摸结束 :withEvent: not called when a drag event moved out of the screen top/bottom,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11608564/