使用 iOS 7 UIViewController 过渡动画放松超过 1 个转场 [英] Unwind with more than 1 segue using iOS 7 UIViewController transition animations

查看:24
本文介绍了使用 iOS 7 UIViewController 过渡动画放松超过 1 个转场的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 iOS7 中引入的 UIViewController 动画过渡.我能够使用 segues 等在 VC 之间来回产生一些非常棒的过渡.

I am using the UIViewController animated transitions introduced in iOS7. I am able to produce some really great transitions going back and forth between VC's using segues etc.

看看我下面的图片:

如果一次只有一个 segue/vc,我可以很容易地来回切换.例如,如果我从屏幕 1 转到屏幕 2,则动画效果完美.然后说我回到 1 或前进到 3,它完美地工作.

I can very easily go back and forth if it is just one segue/vc at a time. For example if, I go from Screen 1 to Screen 2, the animation works perfect. And then say I go back to 1 or forward to 3, it works perfectly.

但是,如果您注意到屏幕 4 底部有一个按钮,上面写着返回屏幕 1"——这是屏幕 1 的展开转场.问题是,我无法让过渡动画工作.事实上,委托方法永远不会被调用.

But, if you notice on screen 4 at the bottom there is a button that says "Back To Screen 1"—this is an unwinding segue to screen 1. The issue is, I can't get the transition animation to work. In fact, the delegate methods never get called.

这是我的设置方式(例如从屏幕 2 到屏幕 3 的动画):

Here is how I have it set up (for example animating from screen 2 to 3):

//This is found in screen 2's view controller .m

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{

    if ([segue.identifier isEqualToString:@"screen2to3"]) {

        UIViewController *destination = segue.destinationViewController;
        destination.transitioningDelegate = self;
        destination.modalTransitionStyle = UIModalPresentationCustom;

    }
}

- (id<UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source {

    STSlideAnimation *animator = [STSlideAnimation new];
    animator.presenting = YES;
    return animator;
}

- (id<UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed {

    STSlideAnimation *animator = [STSlideAnimation new];
    return animator;
}

//This is the unwinding segue action

-(IBAction)returnToScreen2:(UIStoryboardSegue *)segue{

}

这对 screen3 和 screen2 都很有效.动画被双向调用.但是,一次返回多个 vc 时,我无法使任何动画工作.有任何想法吗?如果我需要发布更多示例代码,请告诉我.

This works perfect going both to screen3 and back to screen2. The animation gets called both ways. However, I can't get any animation to work when going back more than one vc at a time. Any ideas? Let me know if I need to post more sample code.

推荐答案

您需要为您希望应用的每种过渡类型制作自定义转场类

#import <UIKit/UIKit.h>

@interface CustomSegue : UIStoryboardSegue

@end


@implementation CustomSegue

 -(void)perform {

 // write your transition code here
 // this code will be called every time transition is made

}

在 storybord 中选择一个 segue - 在检查器中将其类型更改为自定义 - 选择您在上述案例CustomSegue"中创建的自定义类

如果您正确地对其进行了子类化,那么您将找到如下所示的检查器

Select a segue in storybord - in inspector change its type to custom - select custom class you have made in above case "CustomSegue"

If you have subclassed it properly then you will find inspector as below

像往常一样放松,但即使您从第 4 个控制器弹出到第 1 个控制器也会获得相同的效果

Unwind as usual but will get the same effect even if you have poped from 4th controller to 1st controller

这篇关于使用 iOS 7 UIViewController 过渡动画放松超过 1 个转场的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆