xcode 在 Storyboard 中使用自定义 Push Segue
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12957231/
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
Using Custom Push Segue in Storyboard
提问by Ali
In iPhone, when we use push Segue in Storyboard, it always navigates from right
to left
. Can we implement any mechanism that it navigates left
to right
, or down
to top
?
在 iPhone 中,当我们在 Storyboard 中使用 push Segue 时,它总是从 导航right
到left
。我们可以实现它导航任何机制left
来right
,或者down
来top
?
I know about how to create Custom
Segue, but it does not work the same like Push
. Can you help me?
我知道如何创建Custom
Segue,但它不像Push
. 你能帮助我吗?
回答by Ali
If you are developing an App for iOS 5, you can create a class that implement UIStoryboardSegue (to have custom segue), and then override the Perform
method in this way:
如果您正在为 iOS 5 开发应用程序,您可以创建一个实现 UIStoryboardSegue 的类(具有自定义 segue),然后Perform
以这种方式覆盖该方法:
-(void)perform {
UIViewController *sourceViewController = (UIViewController*)[self sourceViewController];
UIViewController *destinationController = (UIViewController*)[self destinationViewController];
CATransition* transition = [CATransition animation];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromLeft;
[sourceViewController.navigationController.view.layer addAnimation:transition forKey:kCATransition];
[sourceViewController.navigationController pushViewController:destinationController animated:NO];
}