Ios touch screen event Guide
This article mainly summarizes two methods for implementing ios touch-screen events, which are simple and practical. For more information, see.
The Code is as follows:
// Add the range to identify the touch event in a function (initialization, etc.)
InfoView = [[UIView alloc] initWithFrame: CGRectMake (20,100,220,280)]; // if the range is reached, no touch is detected.
InfoView. backgroundColor = [UIColor blueColor];
InfoView. alpha = 0.6;
[Self. view addSubview: infoView];
/****************** Monitoring gesture control *****************/ // There are upper, lower, and lower sides, I only used the left and right, and I bet on it.
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 :( uiswipegesturerecognizerdireleft left)];
[InfoView addGestureRecognizer: recognizer];
// Implementation function of the touch event
// Slide Event 1
-(Void) handleSwipeFrom :( UISwipeGestureRecognizer *) recognizer {
// If it slides to the left
If (recognizer. direction = UISwipeGestureRecognizerDirectionLeft ){
NSLog (@ "**************** Slide left ****************" );
}
// Slide to the right
If (recognizer. direction = UISwipeGestureRecognizerDirectionRight ){
NSLog (@ "**************** slide right ****************");
}
If (recognizer. direction = UISwipeGestureRecognizerDirectionDown ){
NSLog ****************");
}
If (recognizer. direction = UISwipeGestureRecognizerDirectionUp ){
NSLog (@ "***************** slide up ****************");
}
}
Method 2:
The Code is as follows:
GSEventRecord header;
GSHardwareKeyInfo key = {0, 0, 0, 1, {'A'}, 1, {'A'}, 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, 1, {'A'}, 1, {'A'}, 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 is all the content of this article. I hope you will like it.