简体   繁体   English

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

[英]iPhone, How do I rotate an UIImageView around a point using Core Animation and CATransform3D?

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. 我想将一个由时钟针(宽度:9px,高度73px)表示的UIImageView从位置(1)移到位置(2),该点围绕图像的一端(3)。 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: 我试图将锚点设置为(0,0)或将图像中心设置为点(517,177),该点是iPad屏幕上的*(3)位置,但是我没有成功:

My degreeToRadians macro is defined in the following way: 我的degreeToRadians宏通过以下方式定义:

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

/* kmPointer is the UIImageView */ / * 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];

How can I make the pointer to rotate around the star marked with (3)? 如何使指针绕着标有(3)的星星旋转?

The Apple docs that show the anchor point image are for OSX. 显示锚点图像的Apple文档适用于OSX。 Here is what it looks like for iOS: alt text http://img.skitch.com/20100728-8ggje4xr8jixa7c2gam96npc9g.png 这是iOS的外观: 替代文字http://img.skitch.com/20100728-8ggje4xr8jixa7c2gam96npc9g.png

So try setting your anchor point to 0.0, 1.0. 因此,请尝试将锚点设置为0.0、1.0。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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