如何使 CGAffineTransform 永久化?

发布于 2024-12-02 12:16:03 字数 767 浏览 4 评论 0原文

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

iphone - 让 CGAffineTransform 永久化

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

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

谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

囍笑 2024-12-09 12:16:03

您可以尝试降低到核心动画级别并应用具有以下属性的变换动画:

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 框架。

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.

一抹微笑 2024-12-09 12:16:03

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

参考:iPhone OS 4.0 中什么是基于块的动画方法?

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

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文