0

I need to be able to tell whenever a UIButton has been forcefully pressed with 3D Touch. Like the Apple Music app where if you 3D Touch on a UICollectionViewCell, a view appears with information about the song.

I have a UICollectionView and there is a UIButton in the cells. I want to do an action whenever a user 3D Touches the UIButton. I looked into this on StackOverflow, but I couldn't understand exactly what to do. Can someone "dumb it down" for me haha. Thanks.

Jacob Cavin
  • 2,169
  • 3
  • 19
  • 47
  • Possible duplicate of [3D touch/Force touch implementation](https://stackoverflow.com/questions/32771947/3d-touch-force-touch-implementation) – Tamás Sengel Sep 29 '17 at 14:36
  • @the4kman I've seen this post. I am fairly new to coding with swift, and I don't quite get what to do with this code. Sorry. – Jacob Cavin Sep 29 '17 at 14:41
  • Hi there. I don't think you actually need a button at all for this. UIView inherits from UIResponder which means you have access to the methods touchesBegan(), touchesMoved(), touchesEnded() to tailor the view's response to touch events. The first answer in the discussion sent to you by @the4kman shows a simple way to read the force of a touch on a UIView subclass. The second answer discusses a second method, namely to create a bespoke gesture recognizer. I'd advise you to play around with the first in a dummy project where you have a simple view that can be touched. – Marcus Sep 29 '17 at 17:21

0 Answers0