我是iPhone编程的新手。我正在尝试旋转UIImage,然后将其动画到屏幕上的其他位置。动画本身工作正常(它可以显示动画),但是当首先与旋转结合时,图像永远不会出现在屏幕上。这是代码片段:
// degrees to rotate animal:
int degreesToRotateAnimal = arc4random_uniform(360);
// create animal:
IBOutlet UIImageView *Animal = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Animal.png"]];
Animal.frame = CGRectMake(20, 50, 100, 20);
Animal.hidden = NO;
// rotate animal:
Animal.transform = CGAffineTransformMakeRotation(degreesToRotateAnimal * (PI / 180.0));
// add animal to subview:
[self.view addSubview:Animal];
// animate animal after rotation:
[UIView animateWithDuration:3
delay:1
options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationCurveLinear
animations:^{
CGAffineTransform transform = CGAffineTransformMakeTranslation(10, 70);
Animal.transform = transform;
}
completion:nil];
// commit:
[UIView commitAnimations];
正如我所说,一切都没有发生:图像没有旋转(我猜)并且没有显示动画。但是,如果省略旋转,动画就可以正常显示图像。有人可以帮帮我吗?
谢谢!