【发布时间】:2025-12-21 04:35:10
【问题描述】:
我正在使用 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];
}
在这里,当我单击按钮导航正常工作,但刷卡不起作用。
【问题讨论】:
-
你需要做什么,因为你的代码刷卡适用于我
-
当我将导航添加到根视图控制器时,它对我不起作用
-
你的意思是在导航或其视图控制器上滑动
-
您在主视图中使用 UIScrollView 吗?如果是,则无法识别上/下手势。
-
@iOSDeveloper,由于 UIScrollView 附带的默认滚动功能,它不起作用,滑动时它会监听滚动事件。如果您禁用 UIScrollView 的“启用滚动”属性,它会起作用。这不是禁用滚动的解决方案。但是您可以使用左/右滑动而不是上/下。
标签: ios objective-c uinavigationcontroller uiswipegesturerecognizer