iPhone,如何使用 Core Animation 和 CATransform3D 绕点旋转 UIImageView?
这就是我想要做的:
(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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
显示锚点图像的 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.