Ios scrollView中的手势识别器不工作
我在scrollView中移动了所有UIElements,以避免加载UIViewcontroller。但是现在视图上的手势识别器不再工作了 我的视图层次结构如下所示:Ios scrollView中的手势识别器不工作,ios,swift,uiview,uiscrollview,uigesturerecognizer,Ios,Swift,Uiview,Uiscrollview,Uigesturerecognizer,我在scrollView中移动了所有UIElements,以避免加载UIViewcontroller。但是现在视图上的手势识别器不再工作了 我的视图层次结构如下所示: let locationLabel: UILabel = { let label = UILabel() label.text = "Standort" label.isUserInteractionEnabled = true //Important! ret
let locationLabel: UILabel = {
let label = UILabel()
label.text = "Standort"
label.isUserInteractionEnabled = true //Important!
return label
}()
override init(frame: CGRect) {
super.init(frame: frame)
self.isUserInteractionEnabled = true //not needed!
contentView.isUserInteractionEnabled = true //Important!
}
func setupViews() {
guard let parent = parentVC else { return }
let locationTap = UITapGestureRecognizer(target: parent, action: #selector(parent.openInGoogleMaps))
locationTap.cancelsTouchesInView = false //Important!
addSubview(contentView)
contentView.addSubview(locationLabel)
locationLabel.addGestureRecognizer(locationTap)
}
- UIViewController(SingleEventController)
- UIScrollView(事件滚动视图)
- UIView(contentView)
- UILabel、UIView、UITableView等
- UIView(contentView)
- UIScrollView(事件滚动视图)
let locationLabel: UILabel = {
let label = UILabel()
label.text = "Standort"
label.isUserInteractionEnabled = true //Important!
return label
}()
override init(frame: CGRect) {
super.init(frame: frame)
self.isUserInteractionEnabled = true //not needed!
contentView.isUserInteractionEnabled = true //Important!
}
func setupViews() {
guard let parent = parentVC else { return }
let locationTap = UITapGestureRecognizer(target: parent, action: #selector(parent.openInGoogleMaps))
locationTap.cancelsTouchesInView = false //Important!
addSubview(contentView)
contentView.addSubview(locationLabel)
locationLabel.addGestureRecognizer(locationTap)
}
我错过了哪一步?
顺便说一句,单击内容视图中的
UITableView
行也不会注册。我在
我的scrollView中的contentView包含所有其他视图,其高度为0,因此无法单击。通过给视图一个高度,它起作用了:
contentView.heightAnchor.constraint(equalTo: self.frameLayoutGuide.heightAnchor, multiplier: 1).isActive = true
您的视图层次结构示例没有提到UITableView或其单元格?我的意思是使用“etc”并不重要,因为标签单击也没有注册。好的,我只是想了解tableView在层次结构中的位置。听起来你有很多相互冲突的手势识别器,你可能需要指定哪些可以一起工作,哪些不能。我想在tableView上长时间点击可能会起作用,但普通点击则不行。看,实际上我只有一个手势识别器。长点击也不起作用。是的,但是ScrollView有平移和收缩识别器,tableView有平移和平移识别器。