iPhone - 设计我自己的viewController转换 [英] iPhone - designing my own viewController transition

查看:73
本文介绍了iPhone - 设计我自己的viewController转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序有一堆viewControllers,我正在尝试从一个viewController到另一个设计我自己的动画过渡。

My app have a bunch of viewControllers and I am trying to design my own animation transition from one viewController to the other.

我找到了这个

- (void)transitionFromViewController:(UIViewController *)fromViewController toViewController:(UIViewController *)toViewController duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion

但这似乎不允许设计我自己的过渡曲线。

but this does not appear to allow designing my own transition curve.

我想要的是在新的viewControllers到达最终位置时创建弹性弹跳等效果和那样的东西。我想将自己的关键帧添加到动画曲线中。

What I want is to create effects like elastic bouncing when the new viewControllers hits the final position and stuff like that. I like to add my own keyframes to the animation curve.

我该怎么做?

谢谢

推荐答案

如果你想设计自己的过渡,你可以为UIViewController创建一个类别并自己编写动画。只有基本动画可用。

If you want to design your own transition you could create a category to UIViewController and write the animations yourself. There are only basic animations already available.

这是你可以做界面的方法:

This is how you could do the interface:

*。h file:

#import <UIKit/UIKit.h>

@interface UIViewController(Transitions)

- (void) presentViewController:(UIViewController *)viewController withPushDirection: (NSString *) direction;
- (void) dismissViewControllerWithPushDirection:(NSString *) direction;

@end

* .m file

*.m file

#import "UIViewControllerWithTransitions.h"
#import <QuartzCore/QuartzCore.h>

@implementation UIViewController(Transitions)

- (void) presentViewController:(UIViewController *)viewController withPushDirection: (NSString *) direction {

    [CATransaction begin];

    CATransition *transition = [CATransition animation];
    transition.type = kCATransitionPush;
    transition.subtype = direction;
    transition.duration = 0.25f;
    transition.fillMode = kCAFillModeForwards;
    transition.removedOnCompletion = YES;

    [[UIApplication sharedApplication].keyWindow.layer addAnimation:transition forKey:@"transition"];        
    [[UIApplication sharedApplication] beginIgnoringInteractionEvents];
    [CATransaction setCompletionBlock: ^ {
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(transition.duration * NSEC_PER_SEC)), dispatch_get_main_queue(), ^ {
            [[UIApplication sharedApplication] endIgnoringInteractionEvents];        
        });
    }];

    [self presentViewController:viewController animated:NO completion:NULL];

    [CATransaction commit];

}

- (void) dismissViewControllerWithPushDirection:(NSString *) direction {

    [CATransaction begin];

    CATransition *transition = [CATransition animation];
    transition.type = kCATransitionPush;
    transition.subtype = direction;
    transition.duration = 0.25f;
    transition.fillMode = kCAFillModeForwards;
    transition.removedOnCompletion = YES;

    [[UIApplication sharedApplication].keyWindow.layer addAnimation:transition forKey:@"transition"];        
    [[UIApplication sharedApplication] beginIgnoringInteractionEvents];
    [CATransaction setCompletionBlock: ^ {
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(transition.duration * NSEC_PER_SEC)), dispatch_get_main_queue(), ^ {
            [[UIApplication sharedApplication] endIgnoringInteractionEvents];        
        });
    }];

    [self dismissViewControllerAnimated:NO completion:NULL];

    [CATransaction commit];

}

@end

and this是一个示例调用:

and this is a sample call:

[self presentViewController: myVC withPushDirection:@"fromRight"]; 

这篇关于iPhone - 设计我自己的viewController转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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