A view displays content, whereas a control is used to modify it in some. A control ( UIControl ) is a subclass of. Views can does not have an UIView action. But Gesture recognizers can is used to add actions for the views.
An image view isn't a control, so it's not designed to respond to input in the same is a control-such as a button-re Sponds. For example, you can ' t simply the create an action method that's triggered when a user taps on an image view. (If you try to Control-drag from the image view to your code, you'll notice that you can ' t select Action in the Connection field.)
Fortunately, it's quite easy to give a view of the same capabilities as a control by adding a gesture recognizer to it. Gesture Recognizers is objects that's attach to a view of the the view to respond to the actions the the- a control Does. Gesture recognizers interpret touches to determine whether they correspond to a specific Gesture, such as a swipe, pinch, or rotation. You can write an action method, the occurs when a gesture recognizer recognizes it assigned gesture, which is exactly WHA t need to does for the image view.
Attach a tap gesture recognizer ( UITapGestureRecognizer ) to the image view, which would recognize when a user has tapped the image view. You can do the easily in your storyboard.
To add a tap gesture recognizer to your image view
Open the Object library. (To open it quickly, choose View > Utilities > Show Object Library.)
The object library, type in the tap gesture filter field to find the Tap Gesture recognizer Object quickly.
Drag a Tap Gesture recognizer object from the object library to your scene, and place it on top of the image view
Swift views and controls