1. Touch Event
System calls automatically
A uitouch represents a finger, hold option, and turn two fingers.
Although it is two fingers, it only performs a touch event
-(void) Touchesbegan: (Nsset *) touches withevent: (Uievent *) event {} start touch events
-(void) touchesmoved: (Nsset *) touches withevent: (Uievent *) event {} finger move events
-(void) touchesended: (Nsset *) touches withevent: (Uievent *) event {} End touch time
-(void) touchescancelled: (Nsset *) touches withevent: (Uievent *) event {} Cancel touch gesture
Get any finger
Uitouch * Touch = [touches anyobject];
Finger-touch View
NSLog (@ "touch.view:%@", Touch.view);
Click Count
NSLog (@ "clicks:%ld", Touch.tapcount);
Position of current finger
Cgpoint currentponit = [Touch LocationInView:touch.view];
Where the last finger was located
Cgpoint previousponit = [Touch PreviousLocationInView:touch.view];
2. Event Distribution
The process of generating and passing events:
When a touch event occurs, it is passed to UIApplication, which receives the event in the queue structure. Passed to the main window, the main window passed to the controller's UIView, traversing the UIView sub-view, looking for the most appropriate uiview to receive.
Responder chain:
The upper level of the class if it is UIView, the child view handles the event, and if it can't handle it, look for his parent view.
The upper level of the class, if Uiviewcontroller, is handled by the owning controller.
Return to the most appropriate UIView
-(UIView *) HitTest: (cgpoint) point withevent: (Uievent *) event {}
Judging the current point is not on the view
-(BOOL) Pointinside: (cgpoint) point withevent: (Uievent *) Event {
return YES;
}
3. Uiimageview Click event
self.imageView.userInteractionEnabled = NO;
3 scenarios in which an event cannot be responded to:
1. When userinteractionenabled is not turned on
2. When the Hidden property is Yes
3, when the Alpha property is 0 o'clock
Converts a point in a yellowview coordinate system to a point with a button as a coordinate system self = Yellowview
Cgpoint buttonpoint = [self convertpoint:point ToView:self.button];
The purpose of this function is to determine whether the point of the current click or touch event is in the current view.
It is hittest:withevent: called ,
-(BOOL) Pointinside: (cgpoint) point withevent: (Uievent *) event; Default returns YES if point was in bounds
4, mobile phone shake a shake
Types of events
-(void) Motionbegan: (uieventsubtype) Motion withevent: (Nullable Uievent *) event {
if (motion = = Uieventsubtypemotionshake) {
NSLog (@ "Shake");
}
}
5. **gesture gestures
Uigesturerecognizerstate:
Start: Uigesturerecognizerstatebegan
Change: uigesturerecognizerstatechanged
Ends: uigesturerecognizerstateended
Cancel: uigesturerecognizerstatecancelled
Failure: uigesturerecognizerstatefailed,
Use two gestures to pinch and rotate
-(BOOL) Gesturerecognizer: (Uigesturerecognizer *) Gesturerecognizer Shouldrecognizesimultaneouslywithgesturerecognizer: (Uigesturerecognizer *) Othergesturerecognizer {
return YES;
}
(1) Tap gesture Tap
UITapGestureRecognizer * Tap1 = [[UITapGestureRecognizer alloc] initwithtarget:self action: @selector (TapAction1:)];
Click once to trigger
tap1.numberoftapsrequired = 1;
[Self.imageview ADDGESTURERECOGNIZER:TAP1];
UITapGestureRecognizer * TAP2 = [[UITapGestureRecognizer alloc] initwithtarget:self action: @selector (TapAction2:)];
Double-click once to trigger
tap2.numberoftapsrequired = 2;
[Self.imageview ADDGESTURERECOGNIZER:TAP2];
If TAP2 executes successfully, let TAP1 fail
[Tap1 REQUIREGESTURERECOGNIZERTOFAIL:TAP2];
(2) long press gesture longpressUilongpressgesturerecognizer * longgesture = [[Uilongpressgesturerecognizer alloc] initwithtarget:self action:@ Selector (longaction:)];
[Self.imageview Addgesturerecognizer:longgesture];
(3) Swipe gesture Swipe
Uiswipegesturerecognizer * swipegesture = [[Uiswipegesturerecognizer alloc] initwithtarget:self action: @selector ( Swipeaction:)];
Set the swipe direction
Swipegesture.direction = Uiswipegesturerecognizerdirectionleft;
[Self.imageview Addgesturerecognizer:swipegesture];
(4) kneading event Pinch
Uipinchgesturerecognizer * pinchgesture = [[Uipinchgesturerecognizer alloc] initwithtarget:self action: @selector ( Pinchaction:)];
Pinchgesture.delegate = self;
[Self.imageview Addgesturerecognizer:pinchgesture];
Self.pin = pinchgesture;
corresponding events
-(void) Pinchaction: (Uipinchgesturerecognizer *) pin {
Self.imageView.transform = Cgaffinetransformscale (Self.imageView.transform, Pin.scale, Pin.scale);
Reset
Pin.scale = 1;
}
(5) Rotating event Rotation
Uirotationgesturerecognizer * rotationgesture = [[Uirotationgesturerecognizer alloc] initwithtarget:self action:@ Selector (rotationaction:)];
Rotationgesture.delegate = self;
[Self.imageview Addgesturerecognizer:rotationgesture];
corresponding events
-(void) Rotationaction: (Uirotationgesturerecognizer *) Rotation {
Self.imageView.transform = Cgaffinetransformrotate (Self.imageView.transform, rotation.rotation);
Reset
rotation.rotation = 0;
}
(6) Drag gestures Pan
Uipangesturerecognizer * pangesture = [[Uipangesturerecognizer alloc] initwithtarget:self action: @selector (panaction :)];
[Self.imageview Addgesturerecognizer:pangesture];
corresponding events
-(void) Panaction: (Uipangesturerecognizer *) Pan {
Gets the offset of the drag
Cgpoint ponit = [Pan TranslationInView:self.view];
Self.imageView.center = Cgpointmake (self.imageview.center.x + ponit.x, self.imageview.center.y + ponit.y);
Reset
[Pan Settranslation:cgpointzero InView:self.imageView];
}
IOS gestures Encyclopedia