2012-07-23 66 views
3

我的问题是很奇怪的,但简单。 我一个子类我的客户的UIScrollView:MyScrollView,其中i禁用滚动:touchesEnded:withEvent:方法当拖动事件移出屏幕顶部的不叫/底部

self.scrollEnabled = NO; 

,这意味着除了

- (void)scrollViewDidScroll:(UIScrollView *)scrollView 

所有其他UIScrollViewDelegate方法不会被调用 和MyScrollView我做的通过检测用户在屏幕上的触摸运动来滚动内容,也就是说不翻动,不反弹,我的实现在触摸移动: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 MyScrollView偏移我自己的方法:withEvent:方法

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    //some implementation according to current content offset 
} 

用户在屏幕上移动手指,当手指离开屏幕表面时, touchesEnded:withEvent:被调用,我可以正确实现我自己的方法。但是,当用户将屏幕表面上的手指从屏幕内部移动到外部或顶部或底部时,然后抬起手指,touchesEnded:withEvent:方法永远不会被调用,它看起来像ios不处理移动界限(顶部或底部)事件作为触摸结束事件,也ios不知道当触摸是在它之外的情况发生了什么事情屏幕边界

有人可能会建议我检测touchesMoved中的当前位置: withEvent:检查它是否入站。这可能工作当运动速度很慢,但是当你移动速度非常快,系统无法检测到每一个点位,这似乎是在一定的时间间隔检测到移动。 任何一个可以帮助我如何检测用户手指是否已移出界限

回答

1

我已解决此问题 bcs UIScrollView做了太多的工作,我们无法自己处理某些事件,幸运的是,UIView可以检测到touche移出界限并将调用touchesEnd:withEvent:方法。 考虑到与UIView的替代MyScrollView的超有太多的工作要做,所以我想出了一个简单的方法来解决: 我加入从UIView的子类的TouchActionDetectView,他们的工作是检测所有用户触摸事件和MyScrollView提供这些事件。当然我必须清除TouchActionDetectView的背景颜色以避免阻止其他视图内容。

+0

是的,touchesEnd在这种情况下叫。 – deko 2014-10-22 13:45:06

3

我认为touchesCancelled:withEvent:方法将被调用!

+1

不,touchchesCledlled:withEvent:也不叫 – Roen 2012-07-24 03:34:13

+0

谢谢,这对我很有效,但是在触摸拖拽(或平移)时,即使平底锅没有完成,它也会接缝着火。 – Gram 2015-06-02 00:20:39

相关问题