iphone视图动画问题

iphone视图动画问题,iphone,caanimation,Iphone,Caanimation,我使用下面的代码来设置视图的动画。它基本上将视图旋转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);

我使用下面的代码来设置视图的动画。它基本上将视图旋转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"];

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

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