ios - Child UIViewController view prevents container UIViewController views from receiving touch events
问题描述
I have a map and some buttons inside main UIViewController and a popup view inside child UIViewController. The problem is that main view of child UIViewController preventing main buttons and map from receiving any touch event!
the structure as following:
- Main UIViewController
- view
- MapView
- UIButton
- view
- Child UIViewController
- view . <-- this prevents main view controllers from receiving any touch events
- popup UIView
- buttons
- view . <-- this prevents main view controllers from receiving any touch events
Edit:
this code pass all events but I don't need to stop popup UIView and buttons events
override func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
print("Passing all touches to the next view (if any), in the view stack.")
return false
}
解决方案
based on @BencePattogato answer, this code fixed my issue. thanks
class UnTouchableView: UIView {
override func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
return subviews.contains(where: {
!$0.isHidden && $0.point(inside: self.convert(point, to: $0), with: event)
})
}
}
推荐阅读
- twig - 如何使用 php 变量代替 .twig 文件?
- python - Snakemake 重建/重新安排工作
- javascript - pdf.js 在给出的示例中更改库的路径
- google-bigquery - 增量加载和 BigQuery
- java - 如何使用 logback 记录 org.springframework.web.context.ContextLoader
- php - 不正确的整数值:第 1 行的列 'lab_id' 的 '{"id":1,"name":"Main Lab}'
- javascript - 在 v-for 循环中设置唯一键
- android - 如何从 android uri 获取 pdf 文件的内容 uri - React Native
- c - 在 void func() 中返回结构
- java - 条件计数总查询