xcode 在故事板中的视图控制器之间滑动手势
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14328336/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Swipe gesture between view controllers in storyboards
提问by David
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 :)
我希望添加一个左右滑动手势以在视图控制器之间进行更改,这可能吗?在故事板中是否有一种简单的方法可以做到这一点?谢谢 :)
回答by Richard C.
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.
故事板允许您在两个视图控制器之间设置转场。我会说首先在视图之间附加 segue,给它一个标识符。
Then use something like
然后使用类似的东西
UISwipeGestureRecognizer * recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(myRightAction)];
[recognizer setDirection:(UISwipeGestureRecognizerDirectionRight)];
[self addGestureRecognizer:recognizer];
to add a swipe recognizer to a view.
向视图添加滑动识别器。
Then in the myRightAction method you'd want to do your segue call like
然后在 myRightAction 方法中,您希望像这样进行 segue 调用
[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.
您可以使用导航视图控制器来制作左右过渡动画。您还可以制作自定义转场。
回答by Enrico Cupellini
on Xcode 5 it is simpler, less code needed:
在 Xcode 5 上它更简单,需要的代码更少:
storyboard -> utility panel -> object Library -> drag and drop the Swipe Gesture Recognizer inside your scene
故事板 -> 实用程序面板 -> 对象库 -> 将滑动手势识别器拖放到场景中
you MUST drag it into the view itself(where the background color appears) so you can see this connection: referencing outlet collections -> view
你必须把它拖到视图本身(背景颜色出现的地方),这样你就可以看到这个连接:引用插座集合 - >视图
add the delegate by dragging the delegate's connection pin to the viewController
通过将委托的连接引脚拖动到 viewController 来添加委托
Show assistant editor -> add an action by ctrl + drag and drop on your delegate class viewController.m
显示助理编辑器 -> 通过 ctrl + 在您的委托类 viewController.m 上拖放添加一个动作
inside that action write
在那个动作里面写
[self performSegueWithIdentifier:@"mySegueIdentifier" sender:self];
回答by jhilgert00
Oops. Posted a comment on accident. Take a look at this answer: https://stackoverflow.com/a/14125580/1126783. You could just use a swipe gesture instead of buttons, and it uses storyboards.
哎呀。发表了关于事故的评论。看看这个答案:https: //stackoverflow.com/a/14125580/1126783。你可以只使用滑动手势而不是按钮,它使用故事板。