检测另一个视图后面的视图的触摸? [英] detect touch on a view behind another view?

查看:43
本文介绍了检测另一个视图后面的视图的触摸?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两种看法

  • 顶视图有一些不透明和一些透明区域
  • 底部视图有一些可点击的按钮.

顶视图完全覆盖了底视图,但是由于顶视图有透明区域,所以仍然可以看到底视图.

The top view is completely covering the bottom view, but since top view has transparent areas, bottom view can still be seen.

但是,我无法再检测到底部视图上的按钮点击,因为顶部视图阻止了它,我该怎么办?

BUT, i cannot detect button clicks on the bottom view anymore since topview is blocking it, what should I do?

有没有办法让顶视图将触摸传递给底视图?

Is there anyway to let top view pass the touches to bottom view?

推荐答案

我自己的问题的解决方案,希望对某人有所帮助.

My solution for my own question, hope it helps someone.

在前视图中,监听 touchesEnded:withEvent 委托.

In the front view, listen for touchesEnded:withEvent delegate.

当此代理触发时,您知道用户正在触摸前视图.

When this delegate fires, you knows that a user is touching the front view.

接下来需要检查手指位置是否触及BOTTOM视图中的特殊区域.

Next you need to check whether the finger position touches special areas in the BOTTOM view.

要做的是:

1) 将点转换为相对于底视图:

1) Convert the point to relative to the bottom view:

UITouch *touch = [touches anyObject];
CGPoint touchPointInLowerView = [touch locationInView:self.lowerViewController.view];
BOOL isLowerButtonClicked = [self.lowerViewController isFingerOnYourButton:touchPointInLowerView];
if(isLowerButtonClicked)
{
 // lower button clicked
}

2) 在下视图

- (BOOL) isFingerOnYourButton:(CGPoint)point
{
 return CGRectContainsPoint(self.aButton.frame, point);
}  

瞧.通过这种方式,我们可以检测底部视图中的点击,即使它被顶部的另一个交互式视图阻止.

voila. In this way, we can detect clicks in bottom view even it is blocked by another interactive view on top.

这篇关于检测另一个视图后面的视图的触摸?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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