滑动 - 右
UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(slideToRightWithGestureRecognizer:)];
swipeRight.direction = UISwipeGestureRecognizerDirectionRight;
[self.view addGestureRecognizer:swipeRight];
滑动左
UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(slideToLeftWithGestureRecognizer:)];
swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;
[self.view addGestureRecognizer:swipeLeft];
在'slideToRightWithGestureRecognizer
'方法中我想编写打开abcViewController的代码,它在故事板上有一个viewcontroller,与'slideToLeftWithGestureRecognizer
'相同,打开xyzViewController,它也在storyboard上有视图控制器。不在程序中使用导航视图控制器
答案 0 :(得分:1)
应该很容易实现:
当您的故事板上连接ViewControllers时,您可以轻松地执行此操作:
- (void)slideToLeftWithGestureRecognizer:(id)sender {
[self performSegueWithIdentifier:@"myConnectionIdentifierHere"]
}
如果不是:
- (void)slideToLeftWithGestureRecognizer:(id)sender {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"myStoryboardName" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"myViewControllerIdentifierHere"];
[self presentViewController:vc animated:YES completion:nil];
}
答案 1 :(得分:1)
您是否考虑过使用UIPageViewController
?或者它必须是滑动而不是平移手势(UIPageViewController以交互方式使用平移手势在视图控制器之间提供导航)。