同一动画块中的两个属性更改具有不同的持续时间。为什么?

发布于 2024-09-28 15:11:01 字数 880 浏览 0 评论 0原文

在以下 UIView 动画块中,我执行了 CGAffineTransformMakeScaleCGAffineTransformMakeRotation,尽管 duration 设置为1.0f, 秤的速度非常快,并且旋转在 1 秒内完成,就像它应该的那样。

这一定是我对如何应用 AffineTransforms 缺乏了解,但我无法弄清楚。

什么给?

编辑:弗拉基米尔的回答非常有效。我两次更改同一属性,而不是更改两个属性。要对 transform 属性进行两次更改,您必须使用初始更改进行 transform,然后将第二个更改添加到该 transform 并然后从那里设置对象的变换。这样,您可以根据需要将任意数量的链接在一起。


CGColorRef color = [[colorArray objectAtIndex:colorIndex] CGColor];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0f];
[[self layer] setFillMode:kCAFillModeForwards];
[self setTransform:CGAffineTransformMakeScale(2.0, 2.0)];
[self setTransform:CGAffineTransformMakeRotation(M_PI / 4)];
[[self layer] setBackgroundColor:color];
[UIView commitAnimations];

In the following UIView animation block, I do a CGAffineTransformMakeScale and a CGAffineTransformMakeRotation, and though the duration is set to 1.0f, the scale goes really fast and the rotation goes in 1 second like it should.

It must be my lack of understanding about how AffineTransforms are applied but I can't figure it out.

What gives?

EDIT: Vladimir's answer worked great. I was changing the same property twice, rather than changing two properties. To make two changes to a transform property, you have to make a transform with the initial change, then add the second change to that transform and then set you object's transform from there. This way, you can chain as many together as you want.


CGColorRef color = [[colorArray objectAtIndex:colorIndex] CGColor];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0f];
[[self layer] setFillMode:kCAFillModeForwards];
[self setTransform:CGAffineTransformMakeScale(2.0, 2.0)];
[self setTransform:CGAffineTransformMakeRotation(M_PI / 4)];
[[self layer] setBackgroundColor:color];
[UIView commitAnimations];

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

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

发布评论

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

评论(1

醉态萌生 2024-10-05 15:11:01
[self setTransform:CGAffineTransformMakeScale(2.0, 2.0)];
[self setTransform:CGAffineTransformMakeRotation(M_PI / 4)];

第二行覆盖第一行的效果。您应该构建整个转换,然后将其应用到您的视图中:

CGAffineTransform tr = CGAffineTransformMakeScale(2.0f,2.0f);
tr = CGAffineTransformRotate(tr, M_PI/4);
[self setTransform: tr];
[self setTransform:CGAffineTransformMakeScale(2.0, 2.0)];
[self setTransform:CGAffineTransformMakeRotation(M_PI / 4)];

2nd line overrides the effect of 1st line. You should construct the whole transform and then apply it to your view:

CGAffineTransform tr = CGAffineTransformMakeScale(2.0f,2.0f);
tr = CGAffineTransformRotate(tr, M_PI/4);
[self setTransform: tr];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文