本文主要是介绍8.5 Detecting Tap Gestures,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
点手势
#import "ViewController.h"
@interface ViewController ()
@property (nonatomic, strong)UITapGestureRecognizer *tapGestureRecognizer;
@end
@implementation ViewController
- (void) handleTaps:(UITapGestureRecognizer*)paramSender{
NSUInteger touchCounter = 0;
for (touchCounter = 0; touchCounter < paramSender.numberOfTouchesRequired;touchCounter++){
CGPoint touchPoint = [paramSender locationOfTouch:touchCounter inView:paramSender.view];
NSLog(@"Touch #%lu: %@",(unsigned long)touchCounter+1, NSStringFromCGPoint(touchPoint));
}
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
/* Create the Tap Gesture Recognizer */
self.tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(handleTaps:)];
/* The number of fingers that must be on the screen */
self.tapGestureRecognizer.numberOfTouchesRequired = 2;
/* The total number of taps to be performed before the gesture is recognized */
self.tapGestureRecognizer.numberOfTapsRequired = 3;
/* Add this gesture recognizer to the view */
[self.view addGestureRecognizer:self.tapGestureRecognizer];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
运行后,用两个手指同时在屏幕上触碰三下
2014-04-10 13:34:59.841 cookbook[980:907] Touch #1: {222.5, 234}
2014-04-10 13:34:59.846 cookbook[980:907] Touch #2: {154.5, 132}
这个在模拟器上怎么模拟呢?
按下option键,一点就会自动变成两根手指点一下哦
所以就是按下option键,点三下
这篇关于8.5 Detecting Tap Gestures的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!