自定义 UINavigationController 动画:CATransition
我有一个 UINavigationController。我将 VC1 设置为 rootViewController,并以编程方式从 VC1 加载 VC2,然后将自定义动画从 VC1 转到 VC2。标准。一切都很好。
现在,我想在两者之间有一个自定义动画,如下所示:
总之,VC1 滑出视图,而 VC2 位于其下方。就像一叠纸一样,您滑开第一张纸 (VC1),从而露出下面的纸 (VC2)。
所以我尝试的是从 VC1 调用以下代码以到达 VC2。但它也有问题:
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];
问题如下:
- VC2 没有在后台修复。它也会滑入(即使我指定了 kCATransitionReveal)。我想让VC2完全固定在后台。
- VC1 淡出。我真的不知道为什么。我没有使用 kCATransitionFade 之类的,所以我看不到淡入淡出来自哪里。
任何关于为什么我没有得到预期结果的建议将非常感激。抱歉,如果这是显而易见的,但我现在已经尝试了几个小时并且感到非常沮丧。
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:
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).
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];
The problems are the following:
- VC2 is not fixed in the background. It kind of slides in as well (even though I specified kCATransitionReveal). I want to be VC2 totally fixed in the background.
- VC1 fades out. I don't really know why. I did not use kCATransitionFade or the like, so I can't see where the fade comes from.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为你应该使用
[[self navigationController] PushViewController:vctwoAnimated:NO];
而不是animated:YES
。I think you should use
[[self navigationController] pushViewController:vctwo animated:NO];
rather thananimated:YES
.我想做到这一点的唯一方法是忘记 UINavigationController 并提出我自己的机制来处理所有事情:
此博客解释了如何...
因此,如果您想在 VC 之间自定义动画,请不要使用 UINavigationController。下面是如上所述在两个 VC 之间交换的示例代码:
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...
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: