ios 我如何使用 performSegueWithIdentifier: sender:?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18550594/
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
How do I use performSegueWithIdentifier: sender:?
提问by OLZ1
I am a new iOS developer and I am currently building a game for the iPhone, and I am writing it in Objective-C.
我是一名新的 iOS 开发人员,目前正在为 iPhone 构建一个游戏,我正在用 Objective-C 编写它。
This question will probably be very easy to answer but I couldn't find it anywhere else. I am using storyboards in this app and I was using them fine when a user pressed a button to go to the next storyboard, however for this when the segue needs to occur automatically I am completely stumped as to how to achieve this.
这个问题可能很容易回答,但我在其他任何地方都找不到。我在这个应用程序中使用了故事板,当用户按下按钮进入下一个故事板时,我使用它们很好,但是当 segue 需要自动发生时,我完全不知道如何实现这一点。
I want to have a logo appear for about five seconds when the app is launched, then the main menu should appear. I am trying to use performSegueWithIdentifier:sender: to achieve this, however I have browsed apple's documentation and it doesn't really answer my question on how this method is used.
我希望在启动应用程序时显示徽标约五秒钟,然后应显示主菜单。我正在尝试使用 performSegueWithIdentifier:sender: 来实现这一点,但是我浏览了苹果的文档,它并没有真正回答我关于如何使用这种方法的问题。
I know what this method is used for, just not what code I need to type to correctly use it.
我知道这个方法是用来做什么的,只是不知道我需要输入什么代码才能正确使用它。
Also if I am using the completely wrong method, or there's a much easier way to achieve what I am trying to do, that would be much appreciated. Any help is useful. Thanks in advance
此外,如果我使用了完全错误的方法,或者有更简单的方法来实现我想要做的事情,那将不胜感激。任何帮助都是有用的。提前致谢
回答by ThisDarkTao
To make a kind of 'splash screen' for your app, just create the view for it in your Storyboard and set it as the entry point (or root of a Navigation Controller etc). Create a segue like you have previously, except drag a segue from the 'Splash' view controller, to the 'Main Menu' controller. With the segue selected, set its Identifier in the Attributes inspector to ShowMainMenu
.
要为您的应用程序制作一种“启动画面”,只需在您的故事板中为其创建视图并将其设置为入口点(或导航控制器等的根目录)。像以前一样创建一个 segue,除了将 segue 从“Splash”视图控制器拖到“主菜单”控制器。选择 segue 后,在属性检查器中将其标识符设置为ShowMainMenu
。
Create a method in the 'Splash' view controller that performs the segue:
在“Splash”视图控制器中创建一个执行转场的方法:
- (void)showMainMenu {
[self performSegueWithIdentifier:@"ShowMainMenu" sender:self];
}
In the 'Splash' view controller's viewDiDLoad
method, add:
在“Splash”视图控制器的viewDiDLoad
方法中,添加:
[self performSelector:@selector(showMainMenu) withObject:nil afterDelay:5.0];
There you have it!
你有它!
回答by DerWOK
This does not answer your segue question. But it solves your root problem of displaying a splash screen in an ios app:
这不能回答您的 segue 问题。但它解决了在 ios 应用程序中显示启动画面的根本问题:
What you describe (and what many app show) is a "Launch Image". No need to code it at your own. In Xcode just go to the settings of your target, then "Summary" and add some launch images.
您所描述的(以及许多应用程序展示的)是“启动图像”。无需自己编写代码。在 Xcode 中,只需转到目标的设置,然后“摘要”并添加一些启动图像。
You have to provide launch images for different display resolutions and devices.
您必须为不同的显示分辨率和设备提供启动图像。
If you want to show the image for at least 5 seconds, see here: increase launch image time on xcode
如果您想显示图像至少 5 秒,请参阅此处:增加 xcode 上的启动图像时间