初始化视图时,我使用以下代码初始化手势识别器。但是,在多次使用手势识别器在视图上方呈现视图并使用presentModalViewController和dismissModelViewController解除视图后,手势识别器将停止处理原始视图。我尝试在视图的dealloc函数中手动释放识别器而不是使用自动释放,但它似乎没有帮助。有没有人有任何想法?谢谢!
另外,我应该提一下,这个问题只发生在设备上,而不是模拟器上。
-(void) initializeGestures {
recognizer = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture:)] autorelease];
//recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture:)];
[(UITapGestureRecognizer *)recognizer setNumberOfTouchesRequired:1];
[self.view addGestureRecognizer:recognizer];
recognizer.delegate = self;
swipeLeftGesture = [[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeGestureLeft:)] autorelease];
//swipeLeftGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeGestureLeft:)];
swipeLeftGesture.direction = UISwipeGestureRecognizerDirectionLeft;
[self.view addGestureRecognizer:swipeLeftGesture];
swipeLeftGesture.delegate = self;
swipeRightGesture = [[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeGestureRight:)] autorelease];
//swipeRightGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeGestureRight:)];
swipeRightGesture.direction = UISwipeGestureRecognizerDirectionRight; // default
[self.view addGestureRecognizer:swipeRightGesture];
swipeRightGesture.delegate = self;
}
-(IBAction) handleSwipeGestureLeft:(UISwipeGestureRecognizer*)sender
{
[self swipeLeft];
}
-(IBAction) handleSwipeGestureRight:(UISwipeGestureRecognizer*)sender
{
[self swipeRight];
}
-(IBAction) handleTapGesture:(UITapGestureRecognizer *) sender {
[self gotoDefinition];
}
答案 0 :(得分:0)
用手势识别器dealloc做了视图吗? 这将导致视图删除手势识别器