将图像定位为“面向”另一个图像

时间:2011-05-08 08:39:10

标签: iphone objective-c animation random uiimageview

大家好,我是法国人,所以请原谅我的英语。

我在屏幕中间有一个静态的图像(image1)。然后我有另一个图像(image2),每次我们打开应用程序是在一个随机位置。 image2是一只头部的猴子。我想要的是每次打开应用程序时猴子的头部都朝向图像1。我认为我们必须使用轮换,但我不确定。我该怎么办呢?

1 个答案:

答案 0 :(得分:0)

计算image1和image2中心之间的角度,然后:

image2.transform = CGAffineTransformMakeRotation(angle);

或者如果你想为它设置动画:

[UIView beginAnimations:@"rotate" context:nil];
[UIView setAnimationDuration:1.0];
image2.transform = CGAffineTransformMakeRotation(angle);
[UIView commitAnimations];