Iphone iOS视图更改与手势问题

Iphone iOS视图更改与手势问题,iphone,ios,ipad,Iphone,Ios,Ipad,这是我的问题:在mainviewcontroller中,我添加了向下滑动手势以关闭另一个视图,但在使用向下滑动手势添加到mainviewcontroller的其他视图中,会打开该特定视图。但是,我不希望在其他视图中而不是在主视图中使用向下滑动手势 //---gesture recognizer - (IBAction) handleSwipes:(UIGestureRecognizer *) sender { UISwipeGestureRecognizerDirection dire

这是我的问题:在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];
}

谢谢

您应该采用
手势识别器委派
协议,并实现
手势识别器: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;
}

我这样做了,但仍然在其他子视图中,我用向下滑动的手势添加到主视图中,指向shakeControll视图???我没有看到您。您仍然可以在子视图上向下滑动吗?这是什么?
shakeControll
?好的,我会尽力澄清我的问题。我有4个视图控制器、主控制器、子控制器(名为shakeController,希望通过向下滑动手势指向此视图),还有2个其他视图添加到主控制器(通过单击按钮指向它们)。在主视图中,向下滑动手势可以正常工作并指向Submanview,但我不希望向下滑动手势也可以在其他两个视图中工作,并将我指向该Submanview。希望问题现在清楚了,感谢是我创建的一个小例子。虽然它不加载新视图,但会在控制台上打印刷卡的
。在这里,我无法在子视图上触发滑动手势。好的,我终于能够使它与您的代码一起工作了。添加了swipeGesture.delegate=self;太好了:)谢谢