Disable 3D touch for UIButton in UITableViewCell

767 Views Asked by At

I have a UITableView with customized UITableViewCells. In the cells I have a UIButton which I don't want to be trigged by the 3D touch event for the cell.

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. 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.

2

There are 2 best solutions below

0
nullforlife On BEST ANSWER

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.

This creates a 3D touch animation for the whole UITableViewCell which looks awesomely beautiful.

1
Tamás Zahola On

Create a UIView and use a UITapGestureRecognizer with a custom force touch gesture recognizer like this DeepPressGestureRecognizer. Set up the gesture recognizers in a way that the DeepPressGestureRecognizer prevents the UITapGestureRecognizer from recognizing.