开发者

How to make a CGAffineTransform permanent?

According to this answer there's a way to make a CGAffineTransform permanent:

iphone - making the CGAffineTransform permanent

but it's not explained... the answer tells about a copy that is generated by the animation but isn't clear how to get it and assign to the original object, so this is the code,开发者_Python百科 how to make it 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];

Thanks


You can try going a level down to Core Animation and apply transform animation with following properties:

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"];

Then you can do other core animations and it should retain the transform. Don't forget to import QuartzCore framework.


In iOS 4.0 or greater Apple recommends using Block based animations

reference: 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];

Not sure if this will solve your problem exactly, but it is a step in the right direction.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜