首页 > 解决方案 > Is there is UITapGesture size limit between regular and plus sized iPhones

问题描述

I am adding a UITapGesture to a UILabel in my code. What is confusing me, when I run the code on an iPhone 7/8 on Hardware or in the Simulator, the TapGesture isn't called. However if I run the exact same code on an iPhone 7/8 PLUS on Hardware or in the Simulator the UITapGesture is fired.

Is there some sort of size limit to touch sizes which is causing this, and how do I get around it?

I have double checked the User Interaction is selected in Xcode.

let myTap = UITapGestureRecognizer(target: self, action: #selector(myAction))
myLabel.addGestureRecognizer(myTap)

This is how I am adding the tap.

标签: iosswift

解决方案


DonMag、Matt 和 Michael 最后都成为了获胜者。

好的,基本上我的视图位于堆栈视图的一部分中。

基本上,自动布局没有调整包含所有具有 GestureRecognizers 的子视图的超级视图的高度。所以即使标签仍然可见,他们也没有收到手势,因为他们超出了父母的范围。但奇怪的是,这只发生在 7 和 8 以及 7 Plus 和 8 Plus 上。所以基本上添加了一个约束来将容器视图的高度设置为等于堆栈视图的高度(强制 Autolayout 为 7/8 重新调整所有内容,这似乎可以解决问题)。

超级烦人,但是感谢您的建议,不胜感激。

在 7 中切换到视图情节提要也很有帮助。


推荐阅读