如何使用故事板在4.2 Xcode中创建自定义模态segue

时间:2011-11-11 17:03:27

标签: ipad sdk ios5

我正在使用故事板来创建我的新iPad项目。我想使用自定义模态segue在视图之间有更好的过渡。我的问题是如何使用自定义模式,是否有任何教程使用自定义模态segues显示?

3 个答案:

答案 0 :(得分:5)

此自定义seque弹回到导航堆栈的根目录。如果要返回一个级别,请使用普通弹出而不是“popToViewController”。我只是喜欢这种方法的名称。

头:

#import <UIKit/UIKit.h>

@interface FlipTopPopToRoot : UIStoryboardSegue

@end

实现:

#import "FlipTopPopToRoot.h"

@implementation FlipTopPopToRoot

- (void) perform {

UIViewController *src = (UIViewController *) self.sourceViewController;
[UIView transitionWithView:src.navigationController.view duration:0.5
                   options:UIViewAnimationOptionTransitionFlipFromTop
                animations:^{
                    [src.navigationController popToViewController:[src.navigationController.viewControllers objectAtIndex:0] animated:NO];;
                }
                completion:NULL];
}

@end

答案 1 :(得分:2)

我正在寻找类似的东西,发现目前的答案有点误导。 TJ提供的当前教程是在导航控制器中执行自定义的segue。如果你正在寻找一个模态segue我相信你需要打电话:

 [self.sourceViewController presentModalViewController:self.destinationViewController animated:NO];

并更改动画的选项。

我写的这篇文章中有更多内容:link

答案 2 :(得分:1)

我发现这是最简单的方法,而不是只是编写一堆代码来滑动框架。

这是自定义segue

- (void) perform {
    UIView *oldView = ((UIViewController *)self.sourceViewController).view;
    UIView *newView = ((UIViewController *)self.destinationViewController).view;

    [oldView.window insertSubview:newView aboveSubview:oldView];
    float offsetY = newView.center.y  - oldView.center.y ;
    //NSLog(@"old y = %f, new y = %f , offsetY = %f", oldView.center.y, newView.center.y, offsetY);


    // assuming newView and oldView both sized to fill screen,
    //   position newView just to the right of oldView

    newView.center = CGPointMake(oldView.center.x + oldView.frame.size.width, oldView.center.y + offsetY);
    //NSLog(@"newView center x = %f y = %f", newView.center.x, newView.center.y);
    // slide newView over oldView, then remove oldView
    [UIView animateWithDuration:0.3
                     animations:^{ newView.center = CGPointMake(oldView.center.x, oldView.center.y + offsetY);}
                     completion:^(BOOL finished){ [oldView removeFromSuperview]; }];
}

希望这有帮助!

相关问题