IOS development (72): Monitoring and capturing light-hitting gestures

Source: Internet
Author: User

1 Preface
Use UITapGestureRecognizer to listen to events that capture users' clicks on the screen.


2. code example
ZYViewController. m

 

[Plain]
(Void) viewDidLoad
{
[Super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
Self. view. backgroundColor = [UIColor whiteColor];
// Create a gesture
Self. tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget: self action: @ selector (handleTaps :)];
/* The screen must have two fingers */
Self. tapGestureRecognizer. numberOfTouchesRequired = 2;
/* You must press 3 */
Self. tapGestureRecognizer. numberOfTapsRequired = 3;
[Self. view addGestureRecognizer: self. tapGestureRecognizer];

}
-(Void) handleTaps :( UITapGestureRecognizer *) paramSender {
NSUInteger touchCounter = 0;
For (touchCounter = 0; touchCounter <paramSender. numberOfTouchesRequired; touchCounter ++ ){
// Obtain the finger position
CGPoint touchPoint = [paramSender locationOfTouch: touchCounter inView: paramSender. view];
NSLog (@ "Touch # % lu: % @", (unsigned long) touchCounter + 1, NSStringFromCGPoint (touchPoint ));
}
}

-(Void) viewDidLoad
{
[Super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
Self. view. backgroundColor = [UIColor whiteColor];
// Create a gesture
Self. tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget: self action: @ selector (handleTaps :)];
/* The screen must have two fingers */
Self. tapGestureRecognizer. numberOfTouchesRequired = 2;
/* You must press 3 */
Self. tapGestureRecognizer. numberOfTapsRequired = 3;
[Self. view addGestureRecognizer: self. tapGestureRecognizer];

}
-(Void) handleTaps :( UITapGestureRecognizer *) paramSender {
NSUInteger touchCounter = 0;
For (touchCounter = 0; touchCounter <paramSender. numberOfTouchesRequired; touchCounter ++ ){
// Obtain the finger position
CGPoint touchPoint = [paramSender locationOfTouch: touchCounter inView: paramSender. view];
NSLog (@ "Touch # % lu: % @", (unsigned long) touchCounter + 1, NSStringFromCGPoint (touchPoint ));
}
}
Running result


The two fingers are displayed on the console three times in a row after the screen is clicked.


15:58:36. 524 UITapGestureTest [4482: c07] Touch #1: {180,321}

15:58:36. 525 UITapGestureTest [4482: c07] Touch #2: {140,119}

 

Related Article

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.