我想添加到我的UIViewController
中:
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture:)];
tapGesture.numberOfTapsRequired = 2;
[self.view addGestureRecognizer:tapGesture];
[tapGesture release];
UITapGestureRecognizer *tapGesture2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture2:)];
tapGesture2.numberOfTapsRequired = 1;
[self.view addGestureRecognizer:tapGesture2];
[tapGesture2 release];
问题是如果用户点击两次则调用了两种方法,而我希望如果用户双击只有一次(handleTapGesture)将被调用,并且如果他进行一次点击它将仅调用第二种方法(handleTapGesture2)
最佳答案
用这个..
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture)];
tapGesture.numberOfTapsRequired = 2;
[self.view addGestureRecognizer:tapGesture];
[tapGesture release];
UITapGestureRecognizer *tapGesture2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture2)];
tapGesture2.numberOfTapsRequired = 1;
[tapGesture2 requireGestureRecognizerToFail: tapGesture];
[self.view addGestureRecognizer:tapGesture2];
[tapGesture2 release];
关于iphone - UIView中有两个UITapGestureRecognizer,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10188834/