UI Fourth Lesson

Source: Internet
Author: User

Main content: Event handling (touch, responder chain)

I. Basic concepts of events

Uievent: Event, which is a hardware-captured object that represents a user-operated device

Divided into three categories: touch events, shaking events, remote control events

Touch events: Users manipulate objects and enter data by touching the device screen. Multi-Touch support

The concept of touch:

UIView supports touch events (because it inherits from Uiresponder) and supports multi-touch

Need to define the UIView subclass to implement touch-related methods

Touches...began//Start Touch

Touches...moved//During touch

touches...ended//End Touch

touches...canceled//Touch Pause

Use touch to implement gestures:

Gestures: a regular touch

Uitouch represents touching a finger on the screen to get the touch time and position

Second, the responder chain

Chain consisting of multiple responder objects

Uiresponder: Responder Class

All objects in iOS that respond to events (touch, shake, remote events) are response events

The system defines an abstract parent class Uiresponder to represent the responder, whose subclass is the responder

To detect a touch view:

The hardware detects a touch operation and passes the information to the uiapplication to begin detection

UIApplication->window->viewcontroller->view, detect all sub-views, finalize the contact location and complete the query process of the responder chain

When a responder is detected, implement methods such as Touchesbegan:withevent, that is, handling events

If the responder does not handle the event, the event is passed down and if no responder handles the event, the touch event is discarded

the sequence of event handling is the opposite of a touch detection query

Touch Child View->view->viewcontroller->window->uiapplication

Four Methods

//Start Touch

-(void) Touchesbegan: (Nsset *) touches withevent: (Uievent *) event

{

}

//During the touch process

-(void) touchesmoved: (Nsset *) touches withevent: (uievent) event

{

}

//Touch Stop

-(void) touchesended: (Nsset *) touches withevent: (uievent) event

{

}

//Touch Pause

-(void) touchescanceled: (Nsset *) touches withevent: (Uievent *) event

{

}

UI Fourth Lesson

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.