这是我的问题:在mainviewcontroller中我添加了向下滑动手势以切换另一个视图,但在其他视图中添加到mainviewcontroller并使用向下滑动手势打开该特定视图。但是,我不想在其他视图中滑动手势而不是主视图。
//---gesture recognizer
- (IBAction) handleSwipes:(UIGestureRecognizer *) sender {
UISwipeGestureRecognizerDirection direction = [(UISwipeGestureRecognizer *) sender direction];
if (direction == UISwipeGestureRecognizerDirectionDown) {
shakeController = [[ShakeViewController alloc]
initWithNibName:@"ShakeViewController" bundle:nil];
CATransition *transition = [CATransition animation];
transition.duration = 0.5;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionMoveIn;
transition.subtype = kCATransitionFromBottom;
transition.delegate = self;
// Next add it to the containerView's layer. This will perform the transition based on how we change its contents.
[self.view.layer addAnimation:transition forKey:nil];
[self.view addSubview:shakeController.view];
}
}
- (void)viewDidLoad {
[super viewDidLoad];
//gesture recognizer
UISwipeGestureRecognizer *swipeGesture = [[UISwipeGestureRecognizer alloc]
initWithTarget:self
action:@selector(handleSwipes:)];
swipeGesture.direction = UISwipeGestureRecognizerDirectionDown;
[self.view addGestureRecognizer:swipeGesture];
[swipeGesture release];
}
由于
答案 0 :(得分:0)
您应该采用UIGestureRecognizerDelegate
协议并实施gestureRecognizer:shouldReceiveTouch:
方法来表明手势识别器是否应该响应。
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
for ( UIView *subview in self.view.subviews ) {
CGPoint point = [touch locationInView:subview];
UIView *hitView = [subview hitTest:point withEvent:nil];
if ( hitView != nil ) {
return NO; // Touching one of the subviews so we will not accept the gesture.
}
}
return YES;
}