ios touchscreen events guide
- 2020-05-07 20:29:53
- OfStack
// in 1 Add a range of functions (initialization, etc.) to identify the touch event
infoView=[[UIView alloc] initWithFrame:CGRectMake(20, 100,220, 280)];// Range, beyond this range you can't detect touch
infoView.backgroundColor=[UIColor blueColor];
infoView.alpha=0.6;
[self.view addSubview:infoView];
/****************** Monitor gesture control *****************/// There is up and down left and right, I only used left and right, on the bet off.
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];
// Touch events Implementation function of
// Sliding event 1
-(void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer{
// If I slide to the left
if(recognizer.direction==UISwipeGestureRecognizerDirectionLeft) {
NSLog(@"**************** The left slide ****************");
}
// If I slide to the right
if(recognizer.direction==UISwipeGestureRecognizerDirectionRight) {
NSLog(@"**************** Slide to the right ****************");
}
if (recognizer.direction==UISwipeGestureRecognizerDirectionDown){
NSLog(@"**************** The sliding ****************");
}
if (recognizer.direction==UISwipeGestureRecognizerDirectionUp){
NSLog(@"**************** Slides up ****************");
}
}
Method 2:
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 is all the content of this article, I hope you can enjoy it.