Swift views and controls

Source: Internet
Author: User

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

    1. Open the Object library. (To open it quickly, choose View > Utilities > Show Object Library.)

    2. The object library, type in the tap gesture filter field to find the Tap Gesture recognizer Object quickly.

    3. 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

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.