Ios touch screen event Guide

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.