2011-04-12 37 views
0

我初始化视图时使用以下代码初始化手势识别器。但是,多次使用手势识别器在视图顶部显示视图并使用presentModalViewController和dismissModelViewController解除视图后,手势识别器将停止在原始视图上工作。我试过在视图的dealloc函数中手动释放识别器,而不是使用autorelease,但它似乎没有帮助。有没有人有任何想法?谢谢!使用presentModalViewController并解散后,GestureRecognizers停止工作

另外,我应该提到,这个问题只发生在设备上,而不是模拟器。

-(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

您应该释放'-initializeRecognizers'方法中的手势识别器,而不是'-dealloc'中。您是否正在释放/自动释放其他位置的手势识别器? – 2011-04-12 06:42:55

回答

0

做了视图与手势识别dealloc当你提出另一个viewController? 这将导致视图移除手势识别器

+0

nope,我不用释放手势识别器。另外,我应该提到这个问题只发生在设备上,而不是模拟器。 – Paul 2011-04-12 06:20:27

+0

你可以告诉我做presentModalViewController和dismissViewController作业的函数吗? – Stan 2011-04-13 05:14:55