IOS. UI advanced. UITouch touch and UIGesture gesture. 01. Events, touch events, ios. uiuigesture

Source: Internet
Author: User

IOS. UI advanced. UITouch touch and UIGesture gesture. 01. Events, touch events, ios. uiuigesture

I. iOS events:

1. event: When you click a cell phone screen on your cell phone, slide your cell phone, and shake your cell phone, the mobile phone responds, some functions of some code are implemented in the application, and completing this process is an event.

2. iOS event type:

(1) touch events, such as clicking a photo to enlarge or clicking a button.

(2) sports events, such as shaking, are typical sports events that implement certain functions through mobile phone movements.

(3) remote control of events. I don't know any examples.

  

  

 

2. Touch events

1. How to handle touch events:

Rewrite the following method to listen to touch events.

2. UITouch touch object

(1) first, let's take a look at what information the touch event will contain: window: the window in which the touch event is generated, view: the view where the touch is generated, whether the tapCount touch is clicked or double-clicked or more, and the phase touch event has a cycle on the screen, that is, the touch starts, the touch points move, the touch ends, and the cancel process. You can use phase to view the status of the current touch time in a cycle. Phase is UITouchPhase type, which is an enumeration:

· UITouchPhaseBegan

· UITouchPhaseMoved

· UITouchPhaseStationary · UITouchPhaseEnded window, view, tapCount, and phase are common attributes in the UITouch class. That is to say, you can use these attributes to create a UITouch object to view the information contained in the touch event. (2)

(3) instance code: Create a project and write the following method in ViewController:

-(Void) touchesBegan :( NSSet *) touches withEvent :( UIEvent *) event {

// Many UITouch objects have been created in the UITouch class. You only need to extract them from them. You do not need to create them again. Therefore, you don't need to use alloc here. You just need to use the UITouch object touch to receive them. AnyObject is any one of the classes.

UITouch * touch = [UITouch anyObject]; obtain a touch point.

NSLog (@ "% @", touch. window) // print the window attribute of touch.

NSLog (@ "% @", touch. view); // print the current view.

NSLog (@ "tapCount: % ld", touch. tapCount); // print the number of clicks.

NSLog (@ "phase: % ld", touch. phase); // the current status.

// Write a switch below to implement different functions based on the number of clicks. The specific code will not be implemented.

Switch (touch. tapCount ){

Case 1:

         

Break;

Case 2:

Break;

Case 3:

Default:

Break;

}

}

(4) Common UITouch Methods

Since it is a common method in the class, if it is an instance method, we can create a UITouch object and call it. If it is a class method, we will directly use the class name, that is, [UITouch]; yes.

  

For example, in (3), we can use the obtained object to call these two methods.

CGPoint point = [touch locationInView: touch. view]; // call this method to obtain the position when you click it. You can get a point by receiving a CGPoint variable.

I don't know how to print this point. If you know it, I 'd like to tell you, thank you.

(5) Transfer of touch events

  

So what is UIGestureRecognizer? What is the first responder? The next blog has a detailed description.

From document:

  

    

Related Article

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.