보기를 초기화 할 때 제스처 인식기를 다음 코드로 초기화합니다. 그러나 제스처 인식기가있는보기를 맨 위에 표시하고 presentModalViewController 및 dismissModelViewController를 사용하여보기를 여러 번 취소하면 제스처 인식기가 원래보기에서 작동하지 않습니다. autorelease를 사용하기보다는 뷰의 dealloc 함수에서 인식기를 수동으로 해제하려고 시도했지만 도움이되지 않습니다. 누구든지 아이디어가 있습니까? 감사!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];
}
제스처 인식기는'-dealloc'가 아니라'-initializeRecognizers' 메소드에서 해제해야합니다. 제스처 인식기를 다른 곳에서도 공개/자동 출시하고 있습니까? –