在故事板中的视图控制器之间滑动手势 [英] Swipe gesture between view controllers in storyboards
问题描述
我希望添加一个左右滑动手势以在视图控制器之间切换,这可能吗?在故事板中是否有一种简单的方法可以做到这一点?谢谢:)
I am looking to add a left and right swipe gesture to change between view controllers, is this possible and is there an easy way to do this in storyboards? Thanks :)
推荐答案
Storyboards 允许您在两个视图控制器之间设置转场.我会说首先在视图之间附加 segue,给它一个标识符.
Storyboards allow you to set up segues between two view controllers. I would say start by attaching segues between the views, give it an identifier.
然后使用类似的东西
UISwipeGestureRecognizer * recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(myRightAction)];
[recognizer setDirection:(UISwipeGestureRecognizerDirectionRight)];
[self addGestureRecognizer:recognizer];
向视图添加滑动识别器.
to add a swipe recognizer to a view.
然后在 myRightAction 方法中,您希望像这样进行 segue 调用
Then in the myRightAction method you'd want to do your segue call like
[self performSegueWithIdentifier: @"MySegue" sender: self];
转到视图或关闭它以离开视图.
to go to a view or dismiss it to leave the view.
您可以使用导航视图控制器来实现左右过渡动画.您还可以制作自定义转场.
You can use Navigation View Controllers to have a right and left transition animation. You can also make custom segues.
这篇关于在故事板中的视图控制器之间滑动手势的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!