有没有人知道为什么只有在 ios5 中第二次点击后才调用 Tap 手势识别器,尽管在 ios6 中它在一次点击后工作正常。
该代码适用于 ios6,我也在单独的项目中尝试了此代码,并且适用于 ios5,我认为它与项目设置相关联,但我不知道是哪个。
我的代码是:
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = questTitle;
//add coretextview
scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
scrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
coreTextView = [[FTCoreTextView alloc] initWithFrame:CGRectMake(20, 20, 280, 0)];
coreTextView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
// set text
[coreTextView setText:[self textForView]];
// set styles
[coreTextView addStyles:[self coreTextStyle]];
// set delegate
[coreTextView setDelegate:self];
[coreTextView fitToSuggestedHeight];
scrollView.scrollEnabled = TRUE;
[scrollView addSubview:coreTextView];
[scrollView setContentSize:CGSizeMake(CGRectGetWidth(scrollView.bounds), CGRectGetHeight(coreTextView.frame) + 40)];
[self.view addSubview:scrollView];
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(pan:)];
tapGesture.delegate = (id <UIGestureRecognizerDelegate>)self;
[coreTextView addGestureRecognizer:tapGesture];
tapGesture.numberOfTapsRequired = 1; // How many taps
tapGesture.numberOfTouchesRequired = 1;
coreTextView.userInteractionEnabled = YES;
tapGesture.cancelsTouchesInView = NO;
scrollView.userInteractionEnabled = YES;
scrollView.exclusiveTouch = NO;
scrollView.delegate = self;
[tapGesture release];
}
- (void)pan:(UITapGestureRecognizer*)sender {
NSLog(@"Pan tap");
}
- (BOOL)gestureRecognizerShouldBegin:(UITapGestureRecognizer *)gestureRecognizer{
NSLog(@"tap");
return YES;
}
- (BOOL)gestureRecognizer:(UITapGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UITapGestureRecognizer *)otherGestureRecognizer{
NSLog(@"tap");
return YES;
}
- (BOOL)gestureRecognizer:(UITapGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
NSLog(@"tap");
return YES;
}