iPhone,如何使用 Core Animation 和 CATransform3D 绕点旋转 UIImageView?

发布于 2024-09-11 12:56:59 字数 1135 浏览 3 评论 0原文

这就是我想要做的:

(1) (2) 
|    /
|   /
|  /
| /
|/
*
(3)

我想将由时钟引脚(宽度:9px,高度 73px)表示的 UIImageView 从位置(1)移动到点(3)(图像的一端)周围的位置(2)。 我尝试将锚点设置为 (0,0) 或将图像中心设置为点 (517,177),即 iPad 屏幕上的 *(3) 位置,但没有成功:

我的 DegreeToRadians 宏定义如下方式:

#define degreesToRadian(x) (M_PI * (x) / 180.0)

/* kmPointer是UIImageView */

NSValue *value = nil;
CABasicAnimation *animation = nil; 
CATransform3D transform;
kmPointer.layer.anchorPoint = CGPointMake(0, 0);
[kmPointer.layer removeAllAnimations]; 
animation = [CABasicAnimation animationWithKeyPath:@"transform"]; 
transform = CATransform3DMakeRotation(degreesToRadian(30), 0.0f, 0.0f, 1.0f); 
value = [NSValue valueWithCATransform3D:transform]; 
[animation setToValue:value]; 
transform = CATransform3DMakeRotation(0.0f, 0.0f, 0.0f, 1.0f); 
value = [NSValue valueWithCATransform3D:transform]; 
[animation setFromValue:value]; 
[animation setAutoreverses:NO]; 
[animation setDuration:1.0f]; 
[animation setRepeatCount:1]; 
[kmPointer.layer addAnimation:animation forKey:nil];

如何让指针围绕标有(3)的星号旋转?

This is what I want to do:

(1) (2) 
|    /
|   /
|  /
| /
|/
*
(3)

I want to move an UIImageView represented by a clock pin (width:9px, height 73px) from position (1) to position (2) around point (3) which is one end of the image.
I tried to set the anchorpoint to (0,0) or to set the image center to point (517,177) which is the *(3) location on the iPad screen, but I had no success:

My degreeToRadians macro is defined in the following way:

#define degreesToRadian(x) (M_PI * (x) / 180.0)

/*
kmPointer is the UIImageView
*/

NSValue *value = nil;
CABasicAnimation *animation = nil; 
CATransform3D transform;
kmPointer.layer.anchorPoint = CGPointMake(0, 0);
[kmPointer.layer removeAllAnimations]; 
animation = [CABasicAnimation animationWithKeyPath:@"transform"]; 
transform = CATransform3DMakeRotation(degreesToRadian(30), 0.0f, 0.0f, 1.0f); 
value = [NSValue valueWithCATransform3D:transform]; 
[animation setToValue:value]; 
transform = CATransform3DMakeRotation(0.0f, 0.0f, 0.0f, 1.0f); 
value = [NSValue valueWithCATransform3D:transform]; 
[animation setFromValue:value]; 
[animation setAutoreverses:NO]; 
[animation setDuration:1.0f]; 
[animation setRepeatCount:1]; 
[kmPointer.layer addAnimation:animation forKey:nil];

How can I make the pointer to rotate around the star marked with (3)?

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

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

发布评论

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

评论(1

回心转意 2024-09-18 12:56:59

显示锚点图像的 Apple 文档适用于 OSX。 iOS 上的效果如下:
替代文本http://img.skitch.com/20100728-8ggje4xr8jixa7c2gam96npc9g.png

尝试将锚点设置为 0.0、1.0。

The Apple docs that show the anchor point image are for OSX. Here is what it looks like for iOS:
alt text http://img.skitch.com/20100728-8ggje4xr8jixa7c2gam96npc9g.png

So try setting your anchor point to 0.0, 1.0.

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