Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/94.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios scrollView中的手势识别器不工作_Ios_Swift_Uiview_Uiscrollview_Uigesturerecognizer - Fatal编程技术网

Ios scrollView中的手势识别器不工作

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

我在scrollView中移动了所有UIElements,以避免加载UIViewcontroller。但是现在视图上的手势识别器不再工作了

我的视图层次结构如下所示:

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等
这看起来像是一个常见问题,因为我在Stackoverflow上发现了很多类似的问题: . 尽管如此,我还是没能解决我的案子

myEventScrollView中的简化代码如下所示:

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有平移和平移识别器。