【发布时间】:2024-01-24 02:22:01
【问题描述】:
我需要在屏幕上移动5个图像并做过渡效果,例如旋转 -> 旋转动画完成时:移动(移动完成时:然后重复过程)
我可以获取 1 张图片来执行此操作,效果很好。
我遇到的问题是我需要为 5 张图片执行此操作;要求是所有图像(或 imageViews)都需要动画同时运行。
我使用了一个自定义对象,里面有一个 UIImageView
-(void)stopRepeatingAnimationForView:(UIView *)view
{
self.enableRepeatingAnimation = NO;
[view.layer removeAllAnimations];
}
- (void)startRepeatingAnimationForView:(UIView *)view
{
self.enableRepeatingAnimation = YES;
[self repeatingAnimationForView:view];
}
- (void)repeatingAnimationForView:(UIView *)view
{
//VICAirplane *planeObj = [self.airplanes objectAtIndex:0];
for (VICAirplane *planeObj in self.airplanes) {
[UIView animateWithDuration:3
delay:1
options:UIViewAnimationOptionCurveLinear
animations:^{
planeObj.imageView.transform = CGAffineTransformRotate(planeObj.imageView.transform, planeObj.angleToRotate);
} completion:^(BOOL finished) {
if (finished==YES) {
[UIView animateWithDuration:5
delay:0.0
options:UIViewAnimationOptionCurveLinear
animations:^{
planeObj.imageView.center = planeObj.rotateToLocation;
} completion:^(BOOL finished) {
if (finished==YES) {
if ( self.enableRepeatingAnimation )
{
CGPoint rotateToLocation = [self generateRandomLocation];
planeObj.rotateToLocation = rotateToLocation;
[self performSelector:@selector(repeatingAnimationForView:) withObject:view afterDelay:0];
}
}
}];
}
}];
} // next
}
如果删除数组中的循环或简单地将其设为 1 长度数组,则动画效果很好。
但是,如果我添加多个动画,它们都是同时进行的,它们会开始丢失完成状态并最终做很多乱七八糟的事情。
我想做的是:
- 循环浏览我的 5 张图片
- 执行我的旋转 -> 移动 -> 在每张图像上重复(永久)动画
但我不确定如何使它适用于存储在数组中的多个 uiimageviews
有没有办法做到这一点?
【问题讨论】:
标签: objective-c uiimageview core-animation uianimation