【问题标题】:iphone view animation problemiphone查看动画问题
【发布时间】:2010-06-19 05:04:49
【问题描述】:

我正在使用以下代码为视图设置动画。它基本上将视图旋转 225 度角。

    [viewToOpen.layer removeAllAnimations];
viewToOpen.hidden = NO;
viewToOpen.userInteractionEnabled = NO;

if (viewToOpen.layer.anchorPoint.x != 0.0f) {
    viewToOpen.layer.anchorPoint = CGPointMake(0.0f, 0.5f);
    viewToOpen.center = CGPointMake(viewToOpen.center.x - viewToOpen.bounds.size.width/2.0f, viewToOpen.center.y);
}

CABasicAnimation *transformAnimation = [CABasicAnimation animationWithKeyPath:@"transform"];
transformAnimation.removedOnCompletion = NO;
transformAnimation.duration = duration;
transformAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
CATransform3D endTransform = CATransform3DMakeAffineTransform(CGAffineTransformMakeRotation(225));

transformAnimation.toValue = [NSValue valueWithCATransform3D:endTransform];
CAAnimationGroup *theGroup = [CAAnimationGroup animation];

theGroup.delegate = self;
theGroup.duration = duration;
[theGroup setValue:[NSNumber numberWithInt:viewToOpen.tag] forKey:@"viewToOpenTag"];
theGroup.animations = [NSArray arrayWithObjects:transformAnimation, nil];
theGroup.removedOnCompletion = NO;
[viewToOpen.layer addAnimation:theGroup forKey:@"flipViewOpen"];

但问题是,在动画结束时,视图会回到原始位置。即使在动画完成后,我也希望将视图保持在相同的位置。我该怎么做?

【问题讨论】:

    标签: iphone caanimation


    【解决方案1】:

    我相信您遇到的问题与在 this question 和 this one 中看到的相同。您要么需要将fillMode 设置为kCAFillModeForwards,要么在动画完成后设置图层的变换。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-03
      • 1970-01-01
      相关资源
      最近更新 更多