0

我目前有一个带有视图控制器和子视图的程序。子视图中包含所有的触摸逻辑。当我将手指滑出子视图时,touchesMoved 方法不会停止处理我的触摸信息。我知道 touchesMoved 方法在我将手指从屏幕上移开之前不会结束,但是必须有一种方法可以让我的程序在我的手指离开子视图后忽略触摸。任何人都知道可以做到这一点的任何此类方法吗?

4

1 回答 1

2
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    CGPoint location = [[touches anyObject] locationInView:yourSubview];
    if (CGRectContainsPoint(yourSubview.frame, location))
    {
        //process touch
    }
    else
    {
        //touch is outside of the subview
    }
}
于 2013-05-30T08:57:54.650 回答