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 __);}