简体   繁体   English

iOS UIScrollView在滚动时取消UIButton touch

[英]iOS UIScrollView cancel UIButton touch on scroll

I have some UIButtons within a UIScrollView, but I do not want to delay the button touches. 我在UIScrollView中有一些UIButtons,但我不想延迟按钮触摸。 However, as soon as the scroll view detects a drag/scroll, I want to cancel the UIButton touch and proceed with the scrolling of the UIScrollView. 但是,只要滚动视图检测到拖动/滚动,我想取消UIButton触摸并继续滚动UIScrollView。

I have included the following... 我已经包括以下内容......

_scrollView.delaysContentTouches = NO;

...but (obviously) the button touch does not cancel when dragged. ...但是(显然)拖动时按钮触摸不会取消。 Does anyone have any suggestions as to how I can implement this functionality? 有没有人对如何实现这个功能有任何建议?

You can override this method of UIScrollView . 您可以覆盖UIScrollView此方法。

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

And in your UIButton, you should add different method for different control events. 在您的UIButton中,您应该为不同的控件事件添加不同的方法。

  1. show highlight effect for UIControlEventTouchDown . 显示UIControlEventTouchDown高亮效果。
  2. trigger button for UIControlEventTouchUpInside | UIControlEventTouchUpOutside UIControlEventTouchUpInside | UIControlEventTouchUpOutside触发按钮UIControlEventTouchUpInside | UIControlEventTouchUpOutside UIControlEventTouchUpInside | UIControlEventTouchUpOutside ; UIControlEventTouchUpInside | UIControlEventTouchUpOutside ;
  3. clear highlight effect for UIControlEventTouchCancel . 清除UIControlEventTouchCancel高亮效果。

You could use scrollViewWillBeginDragging to fire off a notification and handle the button canceling by listening for it in your buttons' code. 您可以使用scrollViewWillBeginDragging触发通知,并通过在按钮的代码中侦听按钮来取消按钮取消。 I think this is what you are trying to do, but I'm not sure if I have understood your question correctly. 我认为这是你想要做的,但我不确定我是否正确理解了你的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM