Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 如何使UIView在不释放触摸的情况下忽略触摸?_Objective C_Ios_Uiview - Fatal编程技术网

Objective c 如何使UIView在不释放触摸的情况下忽略触摸?

Objective c 如何使UIView在不释放触摸的情况下忽略触摸?,objective-c,ios,uiview,Objective C,Ios,Uiview,我在UIScrollView上有一个透明的UIView。UIView通过检查三个TouchsMoved事件来确定是否允许scrollview滚动。事件发生后,我希望视图禁用用户交互,以便发生滚动。用户甚至不应该注意到延迟 但是,在将视图的userInteractionEnabled设置为NO之后,它会一直声明所有TouchsMoved事件,直到发布为止。这意味着用户在能够滚动之前必须放弃视图 在视图发布之前,使用hitTest也不会起作用。移动时不会调用hitTest 我会将触摸事件发送到UIS

我在UIScrollView上有一个透明的UIView。UIView通过检查三个TouchsMoved事件来确定是否允许scrollview滚动。事件发生后,我希望视图禁用用户交互,以便发生滚动。用户甚至不应该注意到延迟

但是,在将视图的userInteractionEnabled设置为NO之后,它会一直声明所有TouchsMoved事件,直到发布为止。这意味着用户在能够滚动之前必须放弃视图

在视图发布之前,使用hitTest也不会起作用。移动时不会调用hitTest

我会将触摸事件发送到UIScrollView,但它很乐意忽略这些事件,因为它有自己隐藏的触摸处理


有没有办法让UIView停止声称触摸事件而不必放弃它?

将UIView隐藏起来。根据文件:

隐藏视图从其窗口中直观地消失,并且不接收输入事件


有关更多信息,请参阅课程参考:

尝试取消触摸:

p、 如有必要,我假设您正在向下一个响应者传播接触:

- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent *)event {
    [super touchesBegan:touches withEvent:event];
    [[self nextResponder] touchesBegan:touches withEvent:event];
}

- (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent *)event {
    [super touchesMoved:touches withEvent:event];
    [[self nextResponder] touchesMoved:touches withEvent:event];
}

- (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent *)event {
    [super touchesEnded:touches withEvent:event];
    [[self nextResponder] touchesEnded:touches withEvent:event];
}

也许这会有帮助@mja我试过hitTest,但它似乎只有在触摸开始时才被调用,而不是在移动时。我将把这一点补充到问题中。谢谢。@jamapag:噢。这应该是userInteractionEnabled。我会解决的。谢谢使用hidden=YES代替userInteractionEnabled=NO会产生相同的问题,所有touchsmoved事件都会发送到隐藏视图,直到用户抬起手指为止。我在类引用中遇到的resignFirstResponder也无法让它工作。不过还是谢谢你。对不起,我还没试过。我找到了一个解决办法,用垂直滚动代替垂直拖动行为(不像听起来那么明显,对角线运动本来就不应该发生)。我仍然想知道这个问题的答案,其他人也一样,也许,我会确保在有时间的时候检查一下。