2 UIViewControllers之间的3D开门动画 [英] 3D Door Open Animation between two UIViewControllers

查看:172
本文介绍了2 UIViewControllers之间的3D开门动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此之前已经问过,但没有样品code要尽可能我知道的计算器,也没有适当的解决方案中。我有一个解决方案,但它看起来废话。我对任何输入和修​​改感激,以获得更逼真的3D门打开/书的封面动画。

This has been asked before, but there is no sample code to be found on stackoverflow and no proper solutions as far as I'm aware. I have a solution, but it looks crap. I'd be grateful for any input and modifications to get a more realistic 3D door open / book cover animation.

目标是拥有UIViewControllers之间的动画,让你得到的效果,如果你是打开门或一本书的封面。的ViewController 2是静态的,在背景中。它的上方,你地方的ViewController 1,涵盖的ViewController 2.动画将打开的ViewController 1(如精装书),并揭示的ViewController 2(第一页这么说来,或任何在门后)。

Aim is to have an animation between UIViewControllers so that you get the effect as if you were opening a door or a book cover. ViewController 2 is static and in the background. Above it you place ViewController 1 which covers ViewController 2. The animation will open ViewController 1 (like a hardcover book) and reveal ViewController 2 (your first page so to say, or whatever is behind the door).

首先要注意的是,因为它是难以覆盖的自定义动画,你不能与UINavigationController的做到这一点。关于如何建立我们的两个ViewControllers一个适当的教程可以在这里找到:的的ViewController动画

First thing to note is that you can't do this with an UINavigationController as it is difficult to overwrite the custom animations. A proper tutorial on how to set up our two ViewControllers can be found here: ViewController Animations

因此​​,一旦一切都设置,这里是它看起来废话我的自定义动画。它基本上看起来好像你正在挤压书左侧的门/盖。没有3D的感觉,我害怕。如何使这更好的将受到欢迎任何建议:

So once everything is setup, here is my custom animation which looks crap. It basically looks as if you are squeezing the door / cover of the book to the left. There is no 3D feel to it, I'm afraid. Any suggestions of how to make this better would be welcome:

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


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

    [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);

    CATransform3D _3Dt = CATransform3DIdentity;
    _3Dt = CATransform3DTranslate(_3Dt, -320, 0, 0);
    _3Dt = CATransform3DRotate(_3Dt, M_PI * 1.5, 0.0, 1, 0.0);
    _3Dt = CATransform3DTranslate(_3Dt, 320, 0, 0);

    activeController.view.layer.transform = _3Dt;

    [UIView commitAnimations];

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


}

我认为主要的问题是,我真的不知道该如何处理 CATransform3DTranslate CATransform3DRotate

下面是一些这方面的职位,但我实在看不出如何将它们应用到3D开门器:

Here are some posts on this, but I can't really see how to apply them to a 3D Door opener:

<一个href=\"http://stackoverflow.com/questions/6531332/how-to-rotate-an-uiimageview-with-catransform3drotate-make-an-effect-like-door-op\">3D门 - 但轴中间

<一个href=\"http://stackoverflow.com/questions/5385898/the-paper-folding-unfolding-effect-in-twitter-for-ipad/6502349#6502349\">3D展开

推荐答案

您必须申请一个小技巧来获得3D的工作:

You have to apply a little trick to get 3D to work:

CATransform3D _3Dt = CATransform3DIdentity;
_3Dt.m34 = 1.0 / -1000;

这将创建透视变换。 1000重新presents从观察者的对象的距离(你可以用这个数值实验,以获得平滑的样子)。

This creates perspective transform. 1000 represents the distance from the viewer to the objects (you can experiment with this value to get a smooth look).

这篇关于2 UIViewControllers之间的3D开门动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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