gpt4 book ai didi

swift - UIScrollView 破坏 subview 中的手势识别器

转载 作者:行者123 更新时间:2023-11-30 13:08:02 25 4
gpt4 key购买 nike

允许 ScrollView 将手势传递给 subview 的正确方法是什么?

最佳答案

您应该向 ScrollView 添加手势识别器,如下所示:

        let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: "handleTap:")
scrollView.addGestureRecognizer(tapGestureRecognizer)

然后像这样处理水龙头:

func handleTap(tap: UITapGestureRecognizer)  {

let location = tap.locationInView(tap.view)

for i in 0..<scrollView.subviews.count{
let subViewTapped = scrollView.subviews[i]
if CGRectContainsPoint(subViewTapped.frame, location) {

print("tapped subview at index\(i)")
// do your stuff here

}
}

}

关于swift - UIScrollView 破坏 subview 中的手势识别器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39100307/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com