ios - uiswipegesturerecognizerdirectionup 和 uinavigationcontroller 不工作?

标签 ios objective-c uinavigationcontroller uiswipegesturerecognizer

我正在使用 uiswipegesturerecognizerdirectionup 和 down。它工作正常,但是当我添加 UINavigationController 时,滑动不起作用。 这是我的代码...

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

}

在这里,当我点击按钮时导航正常工作,但滑动不工作。

最佳答案

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

    }

关于ios - uiswipegesturerecognizerdirectionup 和 uinavigationcontroller 不工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45831712/

相关文章:

ios - 用于在编辑器中的上一个文件和当前文件之间切换的键盘快捷键

ios - 将图像存储到 iPhone 有延迟

ios - UIButton 移动动画

iphone - 从 UIView 子类访问 UINavigationController

iphone - 语法帮助 - 作为对象名称的变量

ios - 使用 Storyboard ios5 时从 View Controller 移动到选项卡栏 Controller

iphone - 在 objective-c 中保留按值传递的变量是否可以?

iOS 更新后首次启动

ios - UINavigationController 中的 UITableViewController 来表示未知深度的树结构

iphone - iPad应用程序行为: a navigationcontroller with a tabbarcontroller with more tabs