Lan Yi iOS Learning seven gestures touches

Source: Internet
Author: User

Today, I learned the methods and applications of gestures in iOS programming, and there are many controls in the screen page, some controls can have click events and users interact directly, can execute corresponding methods, such as Textfield,button,uisegmentcontroll, But static Lableuiimageview and so on need to turn on the interactive switch, add the response gesture to realize the interaction.

Liu Guobin to us in detail seven gestures, including click Touches,uipangesturerecognizer drag, Uilongpressgesturerecognizer long press gesture, Uiscreenedgepangesturerecognizer slide and so on.

An event is an object that the system constantly sends to the application when the user's finger strikes the screen and moves on the screen. The system passes an event to a specific path to an object that can be processed. In iOS, a Uitouch object represents a touch, and a Uievent object represents an event. The event object contains all the touch objects that correspond to the current multi-touch sequence, and can also provide touch objects associated with a particular view or window.

A Responder object is an object that can respond to an event and process it.

Uiresponder is the base class for all responder objects, and it defines the programming interface not only for event handling, but also for common responder behavior.

When the gesture begins to move, let the center point of the image move with the touch point

Case uigesturerecognizerstatechanged:

Self.ii.center=[sender LocationInView:self.view];

Break

When the gesture moves to the end, determine if the image is in the set area, and if you add the picture to the area, note that the coordinates of the image from view to Vie are converted.

Case uigesturerecognizerstateended:

if (Cgrectcontainspoint (Self.vie.frame, Self.ii.center)) {

Cgpoint Old=self.ii.center;

Cgpoint New=[self.view Convertpoint:old ToView:self.vie];

[Self.vie ADDSUBVIEW:SELF.II];

Self.ii.center=new;

Add a post-click gesture to a moving picture

UITapGestureRecognizer *tgr=[[uitapgesturerecognizer

Lan Yi iOS Learning seven gestures touches

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.