自定义UINavigationController动画:CATransition [英] Customise UINavigationController animation: CATransition

查看:178
本文介绍了自定义UINavigationController动画:CATransition的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UINavigationController。我使VC1的rootViewController和编程从VC1加载VC2,然后有自定义动画从VC1到VC2。标准。一切都很好。

I have an UINavigationController. I made VC1 the rootViewController and programatically load VC2 from VC1 and then have the custom animation to go from VC1 to VC2. Standard. Everything is fine and good.

现在,我想在两者之间有一个自定义动画,像这样:

Now, I would like to have a custom animation between the two like so:

总之,VC1滑出视图,而VC2在其下。就像一叠纸,你滑开第一张纸(VC1),从而显示下面的纸张(VC2)。

In sum, VC1 slides out of view while VC2 is beneath it. Just like a stack of paper where you slide away the first sheet (VC1) and thus reveal the sheet beneath (VC2).

所以我试着是下面的代码从VC1调用以获得VC2。但有它的问题:

So what I tried is the following code which is called from VC1 in order to get to VC2. But there are problems with it:

MyVC2 *vctwo = [[[MyVC2 alloc] init] autorelease];

CATransition *transition = [CATransition animation];
transition.duration = 1;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionReveal;
transition.subtype = kCATransitionFromRight;
transition.delegate = self;
[self.navigationController.view.layer addAnimation:transition forKey:nil];

[[self navigationController] pushViewController:vctwo animated:YES];

问题如下:


  1. VC2不是在后台固定的。它也是幻灯片(即使我指定了kCATransitionReveal)。我想要在后台VC2完全固定。

  2. VC1淡出。我真的不知道为什么。我没有使用kCATransitionFade或类似的,所以我看不到褪色来自哪里。

任何建议为什么我不是得到预期的结果将非常感谢。对不起,如果这是显而易见的,但我正在尝试这个小时,真的很沮丧。

Any suggestions why I am not getting the expected results would be very much appreciated. Sorry if this is obvious, but I am trying this for hours now and got really frustrated.

推荐答案

这是忘记UINavigationController,并提出了我自己的机制来处理一切:

I suppose the only way to do this is to forget UINavigationController and come up with my own mechanism to handle everything:

This blog explains how...

因此,如果您想定制自定义广告素材VC之间的动画,不要使用UINavigationController。这里是如上所述在两个VC之间交换的示例代码:

So if you wanted to custom animations between VCs, do not use UINavigationController. Here is sample code to swap between two VCs as described above:

    -(void)slideDoorOpenTo:(UIViewController *)aController duration:(float)aDuration {

    [aController viewWillAppear:YES];
    [activeController viewWillDisappear:YES];

    //aController.view.alpha = 0.0f;
    [self.view insertSubview:aController.view belowSubview:activeController.view]; // so that it is below activeController

    [aController viewDidAppear:YES];

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:aDuration];

    aController.view.transform = CGAffineTransformMakeTranslation(0,0);
    activeController.view.transform = CGAffineTransformMakeTranslation(-320,0);

    [UIView commitAnimations];

    [self performSelector:@selector(animationDone:) withObject:aController afterDelay:aDuration];


}

这篇关于自定义UINavigationController动画:CATransition的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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