在 UIButton 下添加 UIScrollView 后失去点击识别 [英] Losing tap recognition after adding a UIScrollView under a UIButton

查看:35
本文介绍了在 UIButton 下添加 UIScrollView 后失去点击识别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个相邻的 UIScrollView,它们都被带有点击手势识别器的 UIButton 部分覆盖.它们按以下顺序添加到视图中:

I have two adjacent UIScrollViews, both partially covered by a UIButton with a tap gesture recognizer. They are added to the view in this order:

  1. 滚动视图 #1
  2. 按钮
  3. 滚动视图 #2(通过用户交互添加)

两个滚动视图都位于按钮后面"的 z 轴位置,但按钮在与新滚动视图重叠的地方不会收到点击.

Both scrollviews are z-positioned "behind" the button, but the button does not receive taps where it overlaps with the newer scrollview.

有没有办法可以声明将此按钮保持在最上面的点击接收器"?

Is there a way I can declare "keep this button the topmost receiver of taps"?

下面是视图的模型.按钮的红色部分是添加scrollview 2后停止接收tap的区域.

Below is a mockup of the views. The red part of the button is the area that ceases to receive taps after scrollview 2 is added.

推荐答案

我建议按钮没有正确放置在右侧滚动视图上方.我知道您已经设置了 zPosition,但是您应该尝试使用以下方法将按钮置于前面(并将两个滚动视图发送到后面):

I would suggest that the button is not being placed above the right scroll view properly. I know you've set the zPosition, however you should try bringing the button to the front (and sending the two scroll views to the back) using:

[self.view becomeSubviewToFront:button];[self.view sendSubviewToBack:scrollView1];[self.view sendSubviewToBack:scrollView2];

如果按钮位于视图排序的顶部,它应该首先接收触摸事件.

If the button is at the top of the view ordering, it should be receiving the touch events first and foremost.

否则,可能是 UIScrollView 的手势识别器与 UIButton 的手势识别器冲突的问题.尝试执行以下操作以确保其背后的 UIButton 和 UIScrollView 都从其手势识别器接收触摸事件:

Failing this, it could be an issue with the UIScrollView's gesture recogniser's conflicting with the UIButton's gesture recogniser. Try implementing the following to ensure that both the UIButton and UIScrollView behind it are receiving touch events from their gesture recognisers:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {返回是;}

上述 UIGestureRecognizerDelegate 方法的默认返回值为 NO,这可以解释为什么按钮没有接收到触摸事件.您可以查看有关此方法和其他委托方法的更多信息 这里.

The default return value of the above UIGestureRecognizerDelegate method is NO, which could explain why the button isn't receiving the touch events. You can check out more information on this method and other delegate methods here.

这应确保所有手势识别器都能识别其视图中的触摸.

This should ensure that all gesture recognisers are recognising touches within their views.

希望这会有所帮助!

这篇关于在 UIButton 下添加 UIScrollView 后失去点击识别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆