xcode ios segues 没有导航控制器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12278845/
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
ios segues without navigationcontrollers
提问by wvp
I would like to use storyboards for creating my app. I can find a lot of information about how to use it with the navigation- or tabcontroller but I don't wan't either of them.
我想使用故事板来创建我的应用程序。我可以找到很多关于如何将它与导航或选项卡控制器一起使用的信息,但我不想要它们中的任何一个。
My goal is to create an app which has different views but without using a navigation or tabcontroller. How do I do it?
我的目标是创建一个具有不同视图但不使用导航或选项卡控制器的应用程序。我该怎么做?
回答by James
In IOS storyboard, if you don't want to use navigation, then you cannot use push segue. Then, you can use modal segue or custom segue. In modal segue, there are four transitions:
在IOS storyboard中,如果你不想使用导航,那么你不能使用push segue。然后,您可以使用模态转场或自定义转场。在模态转场中,有四种转换:
- Cover Vertical
- Flip Horizontal
- Cross Dissolve
- Partial Curl
- 封面垂直
- 水平翻转
- 交叉溶解
- 部分卷曲
However, all of these pre-defined segue animations can not preform horizontal sliding animation segue. If you want to use horizontal sliding effect, you have to use custom segue. You need to override the function like this:
但是,所有这些预定义的转场动画都不能执行水平滑动动画转场。如果要使用水平滑动效果,则必须使用自定义 segue。您需要像这样覆盖函数:
- (void) perform
{
UIViewController *desViewController = (UIViewController *)self.destinationViewController;
UIView *srcView = [(UIViewController *)self.sourceViewController view];
UIView *desView = [desViewController view];
desView.transform = srcView.transform;
desView.bounds = srcView.bounds;
if(isLandscapeOrientation)
{
if(isDismiss)
{
desView.center = CGPointMake(srcView.center.x, srcView.center.y - srcView.frame.size.height);
}
else
{
desView.center = CGPointMake(srcView.center.x, srcView.center.y + srcView.frame.size.height);
}
}
else
{
if(isDismiss)
{
desView.center = CGPointMake(srcView.center.x - srcView.frame.size.width, srcView.center.y);
}
else
{
desView.center = CGPointMake(srcView.center.x + srcView.frame.size.width, srcView.center.y);
}
}
UIWindow *mainWindow = [[UIApplication sharedApplication].windows objectAtIndex:0];
[mainWindow addSubview:desView];
// slide newView over oldView, then remove oldView
[UIView animateWithDuration:0.3
animations:^{
desView.center = CGPointMake(srcView.center.x, srcView.center.y);
if(isLandscapeOrientation)
{
if(isDismiss)
{
srcView.center = CGPointMake(srcView.center.x, srcView.center.y + srcView.frame.size.height);
}
else
{
srcView.center = CGPointMake(srcView.center.x, srcView.center.y - srcView.frame.size.height);
}
}
else
{
if(isDismiss)
{
srcView.center = CGPointMake(srcView.center.x + srcView.frame.size.width, srcView.center.y);
}
else
{
srcView.center = CGPointMake(srcView.center.x - srcView.frame.size.width, srcView.center.y);
}
}
}
completion:^(BOOL finished){
//[desView removeFromSuperview];
[self.sourceViewController presentModalViewController:desViewController animated:NO];
}];
}
If you still have problem, you can check this post. It also has a youtube video to show you how to implement this custom segue:
如果你还有问题,你可以查看这个帖子。它还有一个 youtube 视频,向您展示如何实现这个自定义转场:
回答by deanWombourne
Why don't you want them? That seems like you're making work for yourself.
你为什么不想要他们?这似乎是你在为自己工作。
You can have a navigation controller that has no visible UI, it's just responsible for pushing and popping other UIViewControllers and then the default push segue type will just work.
你可以有一个没有可见 UI 的导航控制器,它只负责推送和弹出其他 UIViewControllers,然后默认的推送 segue 类型将起作用。
However, if you reallydon't want them you can always make a custom segue classand use that to manage you view controller stack.
但是,如果你真的不想要它们,你总是可以创建一个自定义的 segue 类并使用它来管理你的视图控制器堆栈。