iOS UIScrollView取消滚动上的UIButton触摸

我有一个UIScrollView UIButtons,但我不想延迟button触摸。 但是,只要滚动视图检测到拖/滚动,我想要取消UIButton触摸并继续滚动的UIScrollView。

我已经包括以下…

_scrollView.delaysContentTouches = NO; 

…但(显然)button触摸不会取消拖动时。 有没有人有任何build议,我可以如何实现这个function?

你可以重写这个UIScrollView方法。

 -(BOOL)touchesShouldCancelInContentView:(UIView *)view { return YES; } 

而在你的UIButton中,你应该为不同的控制事件添加不同的方法。

  1. 显示UIControlEventTouchDown高亮效果。
  2. 触发buttonUIControlEventTouchUpInside | UIControlEventTouchUpOutside UIControlEventTouchUpInside | UIControlEventTouchUpOutside ;
  3. 清除UIControlEventTouchCancel高亮效果。

您可以使用scrollViewWillBeginDragging来触发通知,并通过在button代码中侦听button来取消button取消。 我想这就是你想要做的,但我不确定是否正确理解了你的问题。