【问题标题】:UIVIew Flip Vertical AnimationUIVIew 翻转垂直动画
【发布时间】:2011-07-05 21:24:42
【问题描述】:

给定:

[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”设置动画。

我需要获得相同的动画,但要垂直。从顶部翻转或从底部翻转。我环顾四周,没有人真正推荐过工作模型。

我试过了,但是没有运气:

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]

任何输入? 提前致谢。

【问题讨论】:

  • 您应该编辑这个问题,为您的代码使用“代码”布局,使其真正可读。
  • 很抱歉。刚刚改了。
  • 定义“不走运”。运行这段代码会发生什么?
  • 在那 0.5 秒内,您看到图像向上移动,然后突然倒置。

标签: iphone animation flip


【解决方案1】:

我还需要从底部动画翻转。我已经编译了几个解决方案,这对我有用

- (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 和进入视野的新 UIView 的上半部分,在动画开始时是完全不可见的。我需要在这些视图上设置锚点值,以免它们的上半部分被剪裁吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-10-15
  • 2023-04-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多