简体   繁体   中英

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, 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM