With the swift language constantly updated iterations, the pure Swift language writing code is more compact and simple, combined with the use of Storyborad, so that the threshold of the development of Apple app is reduced a lot. It is also recommended to use Interface Builder to build the interface and to write code if necessary, which will not only improve the efficiency of the development, but also help us to better understand the control elements. No more nonsense, get to the point.
As a result of the recent development of an app to use the ImageView response event, to find a lot of information, OC Shadow is too strong, after all, swift itself can do things do not need to write OC. But since the ImageView itself does not support action events, how do I add a click event Trigger action? The strength and convenience of the Stroyborad is then revealed. New (drag) a ImageView click (make sure to check ImageView) attribute inspector, we will find that interaction has two checkbox buttons, namely user interaction Enable and multiple Touch, which shows that ImageView enables interaction with the user, and also supports a number of complex click Actions.
Here are the specific steps: (Xcode version 7.1.1)
1. Create a new ImageView and tick the user interaction enable in the interaction option
2. In the object library, search for tap Gesture recognizer and drag it onto the ImageView, and a tap Gesture will appear on our controller scene. Recognizer and ImageView are outlet collections bound.
3. Select the action event by selecting the Tap Gesture recognizer right-click to bind to code.
4. Run and click Program Test
Put a proxy on ImageView.
Swift-imageview Response to click events