- A variety of events occur during the user's use of the app
- Events in iOS can be divided into 3 major types: Touch events, accelerometer events, remote control events
- Not all objects in iOS can handle events, only objects that inherit Uiresponder can receive and handle events. We call it "responder object."
- UIApplication, Uiviewcontroller, and UIView inherit from Uiresponder, so they are both responder objects that can receive and handle events
//when the finger starts to touch the 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__); //Get Uitouch ObjectUitouch *touch =[touches anyobject]; //gets the current pointCgpoint curp =[Touch locationinview:self]; //Get previous pointCgpoint PreP =[Touch previouslocationinview:self]; //get x-axis offsetCGFloat OffsetX = curp.x-prep.x; //Get y-axis offsetCGFloat OffsetY = curp.y-prep.y; //Modify the view's location (Frame,center,transform)Self.transform =cgaffinetransformtranslate (Self.transform, OffsetX, OffsetY); //self.transform = cgaffinetransformmaketranslation (OffsetX, 0); }//when the finger leaves the view- (void) touchesended: (Nsset *) touches withevent: (Uievent *)Event{NSLog (@"%s", __func__);}//called when a touch event is interrupted (call-in)- (void) touchescancelled: (Nsset *) touches withevent: (Uievent *)Event{NSLog (@"%s", __func__);}
Uiresponder about IOS Event handling