UIButton 和 UILabel 在较小的屏幕上不可点击
UIButton and UILabel not clickable on smaller screens
我创建了一个自定义下拉列表,它是 UIButton 的堆栈视图。并制作了 UIlabel 文本(服务条款)的可点击部分。
两者都在 iphone XR 上完美运行(可以点击它们)。
问题只发生在较小的设备上 (iphone 6,7)。下拉列表中的最后一个 UIButton 可在按钮标题上方点击,而不是在标签或整个按钮上 space。 UILabel(Terms of Service) 完全不可点击。
Iphone XR 运行良好。
Not clickable UIButton
Not clickable UILabel
监听 UILabel tap(在较小的设备上不调用):
@objc func tapLabel(gesture: UITapGestureRecognizer) {
print("TapLabel")
let text = "By upgrading your account, you agree to our Terms of Service."
let termsRange = (text as NSString).range(of: "Terms of Service.")
if gesture.didTapAttributedTextInLabel(label: textTerms, inRange: termsRange) {
if let url = URL(string: "https://xxxxx/terms") {
UIApplication.shared.open(url)
}
} else {
print("Tapped none")
}
}
Interface-builder:
Interface overview
布局约束日志,当我打开下拉菜单时:
"<NSLayoutConstraint:0x2823f4230 UIButton:0x109505a70'Quarterly Subscription - ...'.height == 50 (active)>",
"<NSLayoutConstraint:0x2823f5680 V:[UIButton:0x10950d760'Quarterly Subscription - ...']-(0)-[UIButton:0x109505a70'Quarterly Subscription - ...'] (active)>",
"<NSLayoutConstraint:0x2823f5a40 V:[UIButton:0x109505a70'Quarterly Subscription - ...']-(0)-[UIButton:0x10950d260'Monthly Subscription - 13...'] (active)>",
"<NSLayoutConstraint:0x2823f48c0 'UISV-spacing' V:[UIButton:0x10950d760'Quarterly Subscription - ...']-(0)-[UIButton:0x10950d260'Monthly Subscription - 13...'] (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x2823f4230 UIButton:0x109505a70'Quarterly Subscription - ...'.height == 50 (active)>
任何想法,这种行为的原因是什么?非常感谢。
您可能已将相对于父视图的宽度和高度设置为 label/button,因此它们的尺寸非常小或其他视图位于它们之上
给标签和按钮一些背景颜色,然后在小屏幕上检查你就知道问题了
在调试模式下查看他们的视图层次结构
我创建了一个自定义下拉列表,它是 UIButton 的堆栈视图。并制作了 UIlabel 文本(服务条款)的可点击部分。 两者都在 iphone XR 上完美运行(可以点击它们)。
问题只发生在较小的设备上 (iphone 6,7)。下拉列表中的最后一个 UIButton 可在按钮标题上方点击,而不是在标签或整个按钮上 space。 UILabel(Terms of Service) 完全不可点击。 Iphone XR 运行良好。
Not clickable UIButton
Not clickable UILabel
监听 UILabel tap(在较小的设备上不调用):
@objc func tapLabel(gesture: UITapGestureRecognizer) {
print("TapLabel")
let text = "By upgrading your account, you agree to our Terms of Service."
let termsRange = (text as NSString).range(of: "Terms of Service.")
if gesture.didTapAttributedTextInLabel(label: textTerms, inRange: termsRange) {
if let url = URL(string: "https://xxxxx/terms") {
UIApplication.shared.open(url)
}
} else {
print("Tapped none")
}
}
Interface-builder: Interface overview
布局约束日志,当我打开下拉菜单时:
"<NSLayoutConstraint:0x2823f4230 UIButton:0x109505a70'Quarterly Subscription - ...'.height == 50 (active)>",
"<NSLayoutConstraint:0x2823f5680 V:[UIButton:0x10950d760'Quarterly Subscription - ...']-(0)-[UIButton:0x109505a70'Quarterly Subscription - ...'] (active)>",
"<NSLayoutConstraint:0x2823f5a40 V:[UIButton:0x109505a70'Quarterly Subscription - ...']-(0)-[UIButton:0x10950d260'Monthly Subscription - 13...'] (active)>",
"<NSLayoutConstraint:0x2823f48c0 'UISV-spacing' V:[UIButton:0x10950d760'Quarterly Subscription - ...']-(0)-[UIButton:0x10950d260'Monthly Subscription - 13...'] (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x2823f4230 UIButton:0x109505a70'Quarterly Subscription - ...'.height == 50 (active)>
任何想法,这种行为的原因是什么?非常感谢。
您可能已将相对于父视图的宽度和高度设置为 label/button,因此它们的尺寸非常小或其他视图位于它们之上
给标签和按钮一些背景颜色,然后在小屏幕上检查你就知道问题了
在调试模式下查看他们的视图层次结构