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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 01:51:27  来源:igfitidea点击:

Using Custom Push Segue in Storyboard

iphoneobjective-ciosxcode

提问by Ali

In iPhone, when we use push Segue in Storyboard, it always navigates from rightto left. Can we implement any mechanism that it navigates leftto right, or downto top?

在 iPhone 中,当我们在 Storyboard 中使用 push Segue 时,它​​总是从 导航rightleft。我们可以实现它导航任何机制leftright,或者downtop

I know about how to create CustomSegue, but it does not work the same like Push. Can you help me?

我知道如何创建CustomSegue,但它不像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 Performmethod 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];
}