iphone查看动画问题

Posted

技术标签:

【中文标题】iphone查看动画问题【英文标题】:iphone view animation problem 【发布时间】: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"];

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

【问题讨论】:

【参考方案1】:

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

【讨论】:

以上是关于iphone查看动画问题的主要内容,如果未能解决你的问题,请参考以下文章

谷歌iPhone应用状态栏动画他们是怎么做到的?

按下时隐藏底栏 - Iphone X 上的动画冻结

iPhone 动画

iPhone 上的核心动画性能

iPhone 动画核心图形

iPhone 动画加载屏幕