Swift-imageview Response to click events

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.