Adding support for touch events
At present, the RestaurantDetailViewController
class has an outlet, ratingsView
, connected to a ratings view in the Restaurant Detail screen. It displays a rating of three and a half stars, but you can't change the rating. You will need to support touch events to make the ratings view respond to taps.
Important Information
You can learn more about handling touches at https://developer.apple.com/documentation/uikit/touches_presses_and_gestures/handling_touches_in_your_view.
To support touch events, you'll modify the RatingsView
class to track the user's touches on the screen and use them to determine the rating. Follow these steps:
- Click the
RatingsView
file in the Project navigator and add the following property after thedraw(_:)
method:override var canBecomeFirstResponder: Bool { true }
canBecomeFirstResponder
is a UIControl
property that determines whether an object can become the first responder...