Search code examples
iosobjective-cuinavigationcontrolleruiswipegesturerecognizer

uiswipegesturerecognizerdirectionup and uinavigationcontroller not working?


I'm working with uiswipegesturerecognizerdirectionup and down. It's working properly but when i add UINavigationController swipe not working. This is my code...

//In viewDidLoad

UISwipeGestureRecognizer *gesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(didSwipe:)];
gesture.direction = UISwipeGestureRecognizerDirectionUp | UISwipeGestureRecognizerDirectionDown;
[self.view addGestureRecognizer:gesture];

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onTapViewController:)];
[self.view addGestureRecognizer:tap];


-(void)didSwipe:(UIGestureRecognizer *)gestureRecognizer {

CATransition *animation = [CATransition animation];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromTop];
[animation setDuration:1.25];
[animation setDelegate:self];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
CALayer *layer = [self.view layer];
[layer addAnimation:animation forKey:nil];
[self.view.window addSubview:self.view];

}

- (void) onTapViewController: (UIGestureRecognizer *) gesture {
}

- (IBAction)onClickBtn:(id)sender {

GotoNextViewController *gnvc = [self.storyboard instantiateViewControllerWithIdentifier:@"GNVC"];
[self.navigationController pushViewController:gnvc animated:NO];

}

Here when i click button navigation working properly, but swiping not working.


Solution

  •     UISwipeGestureRecognizer *gesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(didSwipe:)];
        gesture.direction = UISwipeGestureRecognizerDirectionUp | UISwipeGestureRecognizerDirectionDown;
        [self.view addGestureRecognizer:gesture];
    
    
    
    and animation
    
        -(void)didSwipe:(UIGestureRecognizer *)gestureRecognizer {
    
            CATransition *animation = [CATransition animation];
            [animation setType:kCATransitionPush];
            [animation setSubtype:kCATransitionFromTop];
            //    [animation setSubtype:kCATransitionFromBottom];
            [animation setDuration:1.25];
            [animation setDelegate:self];
            [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
            [self.view.layer addAnimation:animation forKey:nil];
    
        }