gpt4 book ai didi

ios - 无法检测到 ScrollView 中的 Swift UI 组件

转载 作者:行者123 更新时间:2023-11-28 07:59:02 27 4
gpt4 key购买 nike

我在 ScrollView 中有一个 UIView。但是这个 UIVIew 中的每个组件甚至它本身都无法检测到手势。

我必须使用文本字段输入昵称,还必须点击 UIView 以启用/禁用男性/女性性别状态。

这是我的代码。即使我尝试了在 Internet 上找到的其他解决方案,它仍然无法正常工作。

let tapViewMale = UITapGestureRecognizer()
tapViewMale.addTarget(self, action:#selector(viewMaleClicked))
self.viewMain!.addGestureRecognizer(tapViewMale)
let tapViewFemale = UITapGestureRecognizer()#imageLiteral(resourceName: "Screen Shot 2017-11-09 at 12.15.55 PM.png")
tapViewFemale.addTarget(self, action:#selector(viewFemaleClicked(_:)))
self.checkboxFemale.isUserInteractionEnabled = true
self.checkboxFemale.addGestureRecognizer(tapViewFemale)
}

@objc func viewMaleClicked(tapGestureRecognizer: UITapGestureRecognizer) {
print ("viewMaleClicked")
if gender == "" || gender == "F" {
print ("1")
checkboxMale.image = UIImage(named: "checked_checkbox")
checkboxFemale.image = UIImage(named: "unchecked_checkbox")
gender = "M"
} else {
print ("2")
checkboxMale.image = UIImage(named: "unchecked_checkbox")
gender = ""
}
}

@objc func viewFemaleClicked(_ sender:AnyObject) {
print ("viewFemaleClicked")
if gender == "" || gender == "M" {
print ("1")
checkboxFemale.image = UIImage(named: "checked_checkbox")
checkboxMale.image = UIImage(named: "unchecked_checkbox")
gender = "F"
} else {
print ("2")
checkboxFemale.image = UIImage(named: "unchecked_checkbox")
gender = ""
}
}

这是屏幕截图。

full component tree

最佳答案

我认为使用透明按钮而不是在 scrollView 中向 uiview 提供手势的简单方法。

@IBAction func onClickBtnMale(_ sender: Any)
{ if gender == "" || gender == "F" {
print ("1")
checkboxMale.image = UIImage(named: "checked_checkbox")
checkboxFemale.image = UIImage(named: "unchecked_checkbox")
gender = "M"
} else {
print ("2")
checkboxMale.image = UIImage(named: "unchecked_checkbox")
gender = ""
}
}
  • 您可以使 uibutton 的宽度与您的 View 相等,并将其用于点击。

关于ios - 无法检测到 ScrollView 中的 Swift UI 组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47193499/

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