简体   繁体   English

在UITableViewCell中为UIButton禁用3D触摸

[英]Disable 3D touch for UIButton in UITableViewCell

I have a UITableView with customized UITableViewCells . 我有一个UITableView定制UITableViewCells In the cells I have a UIButton which I don't want to be trigged by the 3D touch event for the cell. 在单元格中,我有一个UIButton ,我不想被该单元格的3D触摸事件触发。

I want it to work in a similar manner as in Apples messages app , if you take a look there it works in the way that if you press the thumbnail for the message sender image (or initials) you get a different peek & pop from when you press the whole cell. 我希望它以与Apples消息应用程序中类似的方式工作,如果您在其中查看它的工作方式是,如果按消息发件人图像 (或首字母缩写)的缩略图 ,您将获得与众不同的窥视和弹出效果。您按下整个单元格。 Only difference is that I want to completely ignore the peek & pop for my button . 唯一的不同是, 我要完全忽略按钮的窥视和弹出 Anyone out there that knows a good solution to this? 有人知道对此有很好的解决方案吗?

Thank you in advance. 先感谢您。

Create a UIView and use a UITapGestureRecognizer with a custom force touch gesture recognizer like this DeepPressGestureRecognizer . 创建一个UIView并将UITapGestureRecognizer与自定义的强制触摸手势识别器(如DeepPressGestureRecognizer Set up the gesture recognizers in a way that the DeepPressGestureRecognizer prevents the UITapGestureRecognizer from recognizing. DeepPressGestureRecognizer阻止UITapGestureRecognizer识别的方式设置手势识别器。

I solved this by adding a UIButton that covered the whole UITableViewCell and then for the UIButton I did not want to be triggered I created a separate UIView with clear background that I laid on top of the 3D touch triggered UIButton . 我通过添加一个覆盖整个UITableViewCellUIButton来解决此问题,然后为不想被触发的UIButton创建了一个单独的UIView具有清晰的背景,并将其置于3D触摸触发的UIButton之上。

This creates a 3D touch animation for the whole UITableViewCell which looks awesomely beautiful. 这会为整个UITableViewCell创建一个3D触摸动画,看起来非常漂亮。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM