uiswipegesturerecognizerdirectionup 和 uinavigationcontroller 不起作用?
Posted
技术标签:
【中文标题】uiswipegesturerecognizerdirectionup 和 uinavigationcontroller 不起作用?【英文标题】:uiswipegesturerecognizerdirectionup and uinavigationcontroller not working? 【发布时间】:2017-08-23 05:59:43 【问题描述】:我正在使用 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 的“启用滚动”属性,它会起作用。这不是禁用滚动的解决方案。但是您可以使用左/右滑动而不是上/下。 【参考方案1】: 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];
【讨论】:
导航正常,但在根 VC 中刷卡无法正常工作 我正在使用故事板,所以会再检查一次,谢谢... 让我们continue this discussion in chat。【参考方案2】:将您的 GestureRecognizer
添加到您的 navigationController
视图中,如下所示:
[self.navigationController.view addGestureRecognizer:gesture];
[self.navigationController.view addGestureRecognizer:tap];
【讨论】:
以上是关于uiswipegesturerecognizerdirectionup 和 uinavigationcontroller 不起作用?的主要内容,如果未能解决你的问题,请参考以下文章