This article mainly gives you a summary of 2 ways to implement the iOS touch-screen event, simple and practical, the need for small partners can refer to.
The code is as follows:
Inside a function (initialization, etc.), add the scope to identify the touch event
Infoview=[[uiview Alloc] Initwithframe:cgrectmake (20, 100,220, 280)];//range, out of this range will not detect the touch of
Infoview.backgroundcolor=[uicolor Bluecolor];
infoview.alpha=0.6;
[Self.view Addsubview:infoview];
/****************** surveillance gesture control *****************///have up and down, I only used to the left and right, up and down.
Uiswipegesturerecognizer *recognizer;
recognizer = [[Uiswipegesturerecognizer alloc] initwithtarget:self action: @selector (Handleswipefrom:)];
[Recognizer Setdirection: (uiswipegesturerecognizerdirectionright)];
[InfoView Addgesturerecognizer:recognizer];
recognizer = [[Uiswipegesturerecognizer alloc] initwithtarget:self action: @selector (Handleswipefrom:)];
[Recognizer Setdirection: (Uiswipegesturerecognizerdirectionup)];
[Self.view Addgesturerecognizer:recognizer];
recognizer = [[Uiswipegesturerecognizer alloc] initwithtarget:self action: @selector (Handleswipefrom:)];
[Recognizer Setdirection: (Uiswipegesturerecognizerdirectiondown)];
[Self.view Addgesturerecognizer:recognizer];
recognizer = [[Uiswipegesturerecognizer alloc] initwithtarget:self action: @selector (Handleswipefrom:)];
[Recognizer Setdirection: (Uiswipegesturerecognizerdirectionleft)];
[InfoView Addgesturerecognizer:recognizer];
realization function of touch event
Sliding Event 1
-(void) Handleswipefrom: (Uiswipegesturerecognizer *) recognizer{
If you slide to the left,
if (recognizer.direction==uiswipegesturerecognizerdirectionleft) {
NSLog (@ "**************** slide **************** to the left");
}
If you slide right
if (recognizer.direction==uiswipegesturerecognizerdirectionright) {
NSLog (@ "**************** right sliding ****************");
}
if (Recognizer.direction==uiswipegesturerecognizerdirectiondown) {
NSLog (@ "**************** to slide ****************");
}
if (recognizer.direction==uiswipegesturerecognizerdirectionup) {
NSLog (@ "**************** upward sliding ****************");
}
}
Method Two:
The code is as follows:
Gseventrecord header;
Gshardwarekeyinfo key = {0,0,0,0,1,{' a '},1,{' a '},0,0,0,0};
memset (&header, 0, sizeof (header));
Header.type = Kgseventkeydown;
header.infosize = sizeof (Gshardwarekeyinfo);
Header.timestamp = Mach_absolute_time ();
struct
{
Gseventrecord Header1;
Gshardwarekeyinfo Key1;
}fuck = {header, key};
Gssendevent (&fuck, Gsgetpurpleapplicationport ());
Gseventrecord header;
Gshardwarekeyinfo key = {0,0,0,0,1,{' a '},1,{' a '},0,0,0,0};
memset (&header, 0, sizeof (header));
Header.type = Kgseventkeydown;
header.infosize = sizeof (Gshardwarekeyinfo);
Header.timestamp = Mach_absolute_time ();
struct
{
Gseventrecord Header1;
Gshardwarekeyinfo Key1;
}fuck = {header, key};
Gssendevent (&fuck, Gsgetpurpleapplicationport ());
The above mentioned is the entire content of this article, I hope you can enjoy.