Изменение вида iOS с проблемой жестов - PullRequest
0 голосов
/ 02 июня 2011

вот моя проблема: в mainviewcontroller я добавил жест смахивания вниз, чтобы переключить другой вид, но внутри других представлений, добавленных к mainview, с помощью жеста смахивания открывается этот конкретный вид.Тем не менее, я не хочу, чтобы жест проводил вниз в других видах, а не в главном.

//---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];
}

Спасибо

1 Ответ

0 голосов
/ 02 июня 2011

Вы должны принять протокол 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;
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...