スクロールビューがジェスチャをサブビューに渡すことを許可する正しい方法は何ですか?
1 に答える
0
次のように、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
}
}
}
于 2016-08-23T12:07:06.827 に答える