Iphone 使一个uiimageView旋转另一个图像

Iphone 使一个uiimageView旋转另一个图像,iphone,objective-c,xcode,animation,uiimageview,Iphone,Objective C,Xcode,Animation,Uiimageview,这是我的问题。 我想给一个图像设置动画,我想让它改变另一个图像,但我不知道怎么做。我只想让它旋转(不是旋转,而是一个旋转的运动,就像它绕着一个圆旋转一样)。请问我该怎么做 这是我的密码: -(void){ CALayer *orbit1 = [CALayer layer]; orbit1.bounds = CGRectMake(0, 0, 200, 200); orbit1.position = centre.center; orbit1.cornerRadius = 100; orbit1.

这是我的问题。 我想给一个图像设置动画,我想让它改变另一个图像,但我不知道怎么做。我只想让它旋转(不是旋转,而是一个旋转的运动,就像它绕着一个圆旋转一样)。请问我该怎么做


这是我的密码:

-(void){
CALayer *orbit1 = [CALayer layer];
orbit1.bounds = CGRectMake(0, 0, 200, 200);
orbit1.position = centre.center;
orbit1.cornerRadius = 100;
orbit1.borderColor= [UIColor redColor].CGColor;
orbit1.borderWidth = 1.5;

planet1 = [CALayer layer];
planet1.bounds = CGRectMake(0, 0, 44.0, 20.0);
planet1.position = CGPointMake(160, 25);
planet1.contents = (id)([UIImage imageNamed:@"bouletest_05.png"].CGImage);
[orbit1 addSublayer:planet1];

CABasicAnimation *anim1 = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
anim1.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
anim1.fromValue = [NSNumber numberWithFloat:0];
anim1.toValue = [NSNumber numberWithFloat:((360*M_PI)/180)];
anim1.repeatCount = HUGE_VALF;
anim1.duration = 10.0;
[orbit1 addAnimation:anim1 forKey:@"transform"];

[self.view.layer addSublayer:orbit1];
}

然后:

-(void)creation{

imageView2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"abouffer_03.png"]];
[[self view] addSubview:imageView2];
imageView2.center=planet1.center;
}
看最后一行:imageView2.center=planet1.center;问题就在这里

请查看此帖子:。在这里,您将看到一个如何沿任意UIBezierPath设置视图动画的示例

因此,在您的情况下,您需要围绕“锚定”图像创建一个圆形路径:

const CGFloat radius = 100.0f;
UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(center.x-radius, center.y-radius, 2*radius, 2*radius)];
并将带有该路径的CAKeyFrameAnimation添加到要移动的图像视图中。

查看此帖子:。在这里,您将看到一个如何沿任意UIBezierPath设置视图动画的示例

因此,在您的情况下,您需要围绕“锚定”图像创建一个圆形路径:

const CGFloat radius = 100.0f;
UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(center.x-radius, center.y-radius, 2*radius, 2*radius)];

并将带有该路径的CAKeyFrameAnimation添加到要移动的图像视图中。

选中。它解释得很好。检查。它解释得很好。对不起,当我想用该路径向图像视图添加CAKeyFrameAnimation时,我有一个小问题,我不知道怎么做,请你帮忙好吗me@Valentin,跟随链接的博客文章-它展示了如何添加动画。你对这里描述的东西有什么特别的问题吗?是的,我从不使用bezierPAth等。。。当我在xcode-(void){然后你的代码}上写的时候,它不工作,屏幕上什么也没发生哦,对不起,我现在明白了。但现在我有另一个问题,我想使用正在旋转的图像,更准确地说是它的中心,将其分配给其他图像,但我使用中心xcode告诉我请求成员“中心”不是结构或union@valentingougeau你到底想怎么做?(邮编可能是)抱歉,但我有一个小问题,当我想添加CAKeyFrameAnimation与该路径的图像视图,我不知道如何做,请你能帮我吗me@Valentin,跟随链接的博客文章-它展示了如何添加动画。你对这里描述的东西有什么特别的问题吗?是的,我从不使用bezierPAth等。。。当我在xcode-(void){然后你的代码}上写的时候,它不工作,屏幕上什么也没发生哦,对不起,我现在明白了。但现在我有另一个问题,我想使用正在旋转的图像,更准确地说是它的中心,将其分配给其他图像,但我使用中心xcode告诉我请求成员“中心”不是结构或union@valentingougeau你到底想怎么做?(邮政编码可为)