UIView的垂直翻转动画 [英] UIVIew Flip Vertical Animation

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

问题描述

假设:

[UIView beginAnimations:nil context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut]; 
[UIView setAnimationDuration:.5];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:card cache:NO];
 myPic = [UIImage UIImagenamed: @"mySecondImage.png"];
[UIView commitAnimations];[/CODE]

哪个动画myPic向左一个向右翻转

Which animates 'myPic' right to left with a flip.

我需要得到同样的动画,但垂直。从顶部翻转或上下翻页。我环顾四周,没有一个人真的有一个工作模型建议。

I need to get the same animation, but vertically. Flip from Top or Flip from Bottom. I looked around, no one really had a working model suggested.

我想这一点,到目前为止,还没有运气:

I tried this, yet, no luck:

float duration = .5;
CABasicAnimation* animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.x"];
animation.fromValue = [NSNumber numberWithDouble:0.0f * M_PI];
animation.toValue = [NSNumber numberWithDouble:1.0f * M_PI];
animation.duration = duration;
animation.removedOnCompletion = NO;
animation.fillMode = kCAFillModeBoth;
animation.repeatCount =1;;
animation.beginTime = CACurrentMediaTime();
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
card.layer.anchorPoint = CGPointMake(0.5, 1.0);
[card.layer addAnimation:animation forKey:@"rotationX"];[/CODE]

任何输入?
先谢谢了。

Any input? Thanks in advance.

推荐答案

我还需要从底部动画翻转。我已经编制了几个解决方案,这对我的作品

I've also needed flip from bottom animation. I've compiled couple solutions and this works for me

- (CATransform3D) makeRotationAndPerspectiveTransform:(CGFloat) angle {
    CATransform3D transform = CATransform3DMakeRotation(angle, 1.0f, 0.0f, 0.0f);
    transform.m34 = 1.0 / -500;
    return transform;
}

- (void) flipFromBottom {

    //setup firstView to be visible
    view1.layer.transform =  CATransform3DMakeRotation(0, 1.0f, 0.0f, 0.0f);
    view1.hidden = NO;

    // setup secondView to be partialy rotated and invisible
    view2.layer.transform = [self makeRotationAndPerspectiveTransform:M_PI/2];
    view2.hidden = YES;

    // making sure that both views have the same position
    view2.frame = view1.frame;

    CFTimeInterval duration =  2.0;

    [UIView animateWithDuration:duration/2 
                          delay:0
                        options:UIViewAnimationCurveEaseIn
                     animations:^{
                         view1.layer.transform = [self makeRotationAndPerspectiveTransform:-M_PI / 2];
                     } 
                     completion:^(BOOL finished){
                         view1.hidden = YES;
                         view2.hidden = NO;
                         [UIView animateWithDuration:duration /2 
                                               delay:0
                                             options:UIViewAnimationCurveEaseOut
                                          animations:^{
                             view2.layer.transform =  CATransform3DMakeRotation(0.0f, 1.0f, 0.0f, 0.0f);
                                          }
                                          completion:NULL];
                     }];
}

这篇关于UIView的垂直翻转动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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