uiswipegesturerecognizerdirectionup 和 uinavigationcontroller 不工作?
uiswipegesturerecognizerdirectionup and uinavigationcontroller not working?
我正在使用 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];
}
在这里,当我点击按钮导航时工作正常,但滑动不工作。
像这样将您的 GestureRecognizer
添加到您的 navigationController
视图中:
[self.navigationController.view addGestureRecognizer:gesture];
[self.navigationController.view addGestureRecognizer:tap];
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];
}
我正在使用 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];
}
在这里,当我点击按钮导航时工作正常,但滑动不工作。
像这样将您的 GestureRecognizer
添加到您的 navigationController
视图中:
[self.navigationController.view addGestureRecognizer:gesture];
[self.navigationController.view addGestureRecognizer:tap];
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];
}