简体   繁体   English

在故事板中的视图控制器之间滑动手势

[英]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 allow you to set up segues between two view controllers. 故事板允许您在两个视图控制器之间设置segue。 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. 您还可以制作自定义segues。

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 storyboard - > utility panel - > object Library - >将Swipe Gesture Recognizer拖放到场景中

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];

Oops. 哎呀。 Posted a comment on accident. 发表意外评论。 Take a look at this answer: https://stackoverflow.com/a/14125580/1126783 . 看看这个答案: https//stackoverflow.com/a/14125580/1126783 You could just use a swipe gesture instead of buttons, and it uses storyboards. 您可以使用滑动手势而不是按钮,它使用故事板。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM