如何使CGAffineTransform永久化?

时间:2011-08-31 21:06:58

标签: iphone ios cgaffinetransform

根据这个答案,有一种方法可以使CGAffineTransform永久化:

iphone - making the CGAffineTransform permanent

但是没有解释......答案讲述了动画生成的副本,但不清楚如何获取并分配给原始对象,所以这是代码,如何使其永久化?

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.3];

[UIView setAnimationRepeatAutoreverses:NO];
[UIView setAnimationRepeatCount:1];

[UIView setAnimationDelegate:self];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];

float angleRadians = 180 * ((float)M_PI / 180.0f);
CGAffineTransform t = CGAffineTransformMakeRotation(angleRadians);

self.myView.transform = t;
[self.myView setCenter:CGPointMake(160, 220)];

[UIView commitAnimations];

由于

2 个答案:

答案 0 :(得分:1)

您可以尝试向下进入Core Animation并使用以下属性应用变换动画:

CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform"];
animation.fromValue = [NSValue valueWithCATransform3D: t];
animation.toValue = [NSValue valueWithCATransform3D: t];
animation.duration = 0.0;
animation.removedOnCompletion = NO;
animation.fillMode = kCAFillModeBoth;
[yourView.layer addAnimation:animation forKey:@"transform"];

然后你可以做其他核心动画,它应该保留变换。不要忘记导入QuartzCore框架。

答案 1 :(得分:0)

在iOS 4.0或更高版本中,Apple建议使用基于块的动画

参考:What are block-based animation methods in iPhone OS 4.0?

    [UIView animateWithDuration:0.3 
                      delay:0 
                    options:UIViewAnimationOptionCurveEaseOut 
                 animations:^{ self.myView.transform = CGAffineTransformMakeRotation(M_PI) } 
                 completion:NULL];

不确定这是否能完全解决您的问题,但这是朝着正确方向迈出的一步。