iPhone,如何使用Core Animation和CATransform3D围绕一个点旋转UIImageView? [英] iPhone, How do I rotate an UIImageView around a point using Core Animation and CATransform3D?

查看:139
本文介绍了iPhone,如何使用Core Animation和CATransform3D围绕一个点旋转UIImageView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这就是我想要做的事情:

This is what I want to do:

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

我想要将由时钟引脚(宽度:9px,高度73px)表示的UIImageView从位置(1)移动到位置(2)围绕作为图像一端的点(3)。
我试图将anchorpoint设置为(0,0)或将图像中心设置为指向(517,177),这是iPad屏幕上的*(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:

我的degreeToRadians宏按以下方式定义:

My degreeToRadians macro is defined in the following way:

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

/ *
kmPointer是UIImageView
* /

/* 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];

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

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

推荐答案

显示锚点图像的Apple文档适用于OSX。以下是iOS的样子:
alt text http://img.skitch .com / 20100728-8ggje4xr8jixa7c2gam96npc9g.png

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

因此,请尝试将锚点设置为0.0,1.0。

So try setting your anchor point to 0.0, 1.0.

这篇关于iPhone,如何使用Core Animation和CATransform3D围绕一个点旋转UIImageView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆