Introduction to iOS event processing-UIResponder, iosuiresponder

Source: Internet
Author: User

Introduction to iOS event processing-UIResponder, iosuiresponder

  • When a user uses an app, various events are generated.
  • Events in iOS can be divided into three types: Touch events, accelerator events, and remote control events.
  • In iOS, not all objects can process events. Only objects that inherit UIResponder can receive and process events. We call it the "response object"
  • UIApplication, UIViewController, and UIView are all inherited from UIResponder. Therefore, they are all responder objects that can receive and process events.

 

// When the finger starts to touch view // NSArray, Dictionary, NSSet (unordered)-(void) touchesBegan :( NSSet *) touches withEvent :( UIEvent *) event {NSLog (@ "% ld", touches. count); NSLog (@ "% s" ,__ func _);} // when the finger moves on the view-(void) touchesMoved :( NSSet *) touches withEvent :( UIEvent *) event {NSLog (@ "% s" ,__ func _); // obtain the UITouch object UITouch * touch = [touches anyObject]; // obtain the current vertex CGPoint curP = [touch locationInView: self]; // obtain the previous vertex CGPoint preP = [touch previuslocationinview: self]; // obtain the X axis offset CGFloat offsetX = curP. x-preP. x; // obtain the Y axis offset CGFloat offsetY = curP. y-preP. y; // modify the view position (frame, center, transform) self. transform = CGAffineTransformTranslate (self. transform, offsetX, offsetY); // self. transform = CGAffineTransformMakeTranslation (offsetX, 0);} // when your finger leaves this view-(void) touchesEnded :( NSSet *) touches withEvent :( ui* event *) event {NSLog (@ "% s" ,__ func _);} // call (CALL)-(void) touchesCancelled :( NSSet *) when the touch event is interrupted *) touches withEvent :( UIEvent *) event {NSLog (@ "% s" ,__ func __);}

 

 

 

 

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.