我有2个UIScrollView。它们不是彼此的子视图。一个只是坐在另一个上面作为叠加,用于获得这种效果:
现在,我在第二个ScrollView(下面的那个)上有一个UIButton
。
我无法点击此按钮,因为顶部滚动视图捕获所有触摸。
所以这就是我想要实现的目标。但是我被困住了。
这是我的代码。请帮我解决它的错误:
@IBAction func bufferviewCliked (sender: UITapGestureRecognizer) {
// First I try to get the point of the object clicked inside as a point on
// the main self.view
let locationInMainView = sender.location(in: self.view)
// Next I try to convert that point, into a point on my backgroundScrollView
let touchPointInSecondView = self.view.convert(locationInMainView, from: backGround)
// If the point intersects with the point on the UIButton in the backgroundScrollView
// Then print hi
if followButton.frame.contains(touchPointInSecondView) {
print("HI")
}
}
问题是我的点坐标错了,我不确定我是否使用了正确的东西。
答案 0 :(得分:0)
您可以从按钮
获取locationInView@IBAction func bufferviewCliked (sender: UITapGestureRecognizer) {
let location = sender.location(in: followButton)
// If the point intersects with the point on the UIButton in the backgroundScrollView
// Then print hi
if followButton.bounds.contains(location) {
print("HI")
}
}