Swift:在另一个UIView下面的UIView的hitTest [英] Swift: hitTest for UIView underneath another UIView

查看:677
本文介绍了Swift:在另一个UIView下面的UIView的hitTest的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在RedOrGreenUIView之上有TransparentUIView。 TransparentUIView附加了一个UILongPressGestureRecognizer。一旦用户开始长时间触摸,我会检查此LongPressGesture的.Changed状态,并在hitTest下执行:

I have TransparentUIView on top of RedOrGreenUIView. TransparentUIView has a UILongPressGestureRecognizer attached to it. Once user begins a long touch on it, I check for .Changed status of this LongPressGesture, and execute below hitTest:

var p:CGPoint = rec.locationInView(self.view)
var selectedView = view.hitTest(p, withEvent: nil)
if selectedView != nil {
   if selectedView == TransparentUIView {
       println("TransparentUIView is being touched")
   }
}

我将TransparentView视为精选。但是我需要能够同时在RedOrGreenUIView上执行hitTest,它位于TransparentUIView下面。我无法理解这一点。请帮忙。

I get TransparentView as selectedView fine. However I need to be able to conduct a hitTest on RedOrGreenUIView at the same time, which is underneath TransparentUIView. I cant get my head around to accomplishing this. Please help.

推荐答案

如果有一个UIView接触到了,下面的其他人都没有得到任何东西。

If one UIView gets touches, others underneath don't get any.

所以要么你有一个中心类可以将触摸传递给你的UIView对象,要么第一个UIView(顶部的那个)将它的UITouch对象传递给UIView在下面并执行hitTest。

So either you can have a central class that passes touches to both your UIView objects, or the first UIView, the one that is on top, passes its UITouch object to the UIView underneath and conducts the hitTest.

这篇关于Swift:在另一个UIView下面的UIView的hitTest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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