我有一个两个图像的图像数组,重复这些图像使鸟儿拍打翅膀。
如何让阵列移动?
我有这个数组:
NSArray *imageNames = @[@"bird1.png", @"bird2.png"];
NSMutableArray *birdflapping = [[NSMutableArray alloc] init];
for (int i = 0; i < imageNames.count; i++) {
[birdflapping addObject:[UIImage imageNamed:[imageNames objectAtIndex:i]]];
}
UIImageView *animationImageView = [[UIImageView alloc] initWithFrame:CGRectMake(60, 95, 86, 193)];
animationImageView.animationImages = birdflapping;
animationImageView.animationDuration = 1;
[self.view addSubview:animationImageView];
[animationImageView startAnimating];
如何使阵列(作为一个整体)移动?
答案 0 :(得分:0)
NSArray *animationArray=[NSArray arrayWithObjects:
[UIImage imageNamed:@"images.jpg"],
[UIImage imageNamed:@"images1.jpg"],
[UIImage imageNamed:@"images5.jpg"],
[UIImage imageNamed:@"index3.jpg"],
nil];
UIImageView *animationView=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0,320, 460)];
animationView.backgroundColor=[UIColor purpleColor];
animationView.animationImages=animationArray;
animationView.animationDuration=1.5;
animationView.animationRepeatCount=0;
[animationView startAnimating];
[self.view addSubview:animationView];
答案 1 :(得分:0)
这是您要移动的动画图像,该图像由图像视图绘制并包含在图像视图中。要移动图像,您可以移动图像视图。一种方法是调整视图的center
属性的位置。另一种可能性是使用更多的图像,动画中的每一帧都显示鸟向前移动了一点。
也就是说,有更好的方法可以做你想做的事。你应该使用SpriteKit或Cocos2D来研究精灵动画。
答案 2 :(得分:0)
你可以试试这种方式
UIImageView * animatedImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 200,200)];
NSArray *imageNames = @[@"bird1.png", @"bird2.png"];
animTime =.0;
[animatedImageView setAnimationImages:imageNames] ;
animatedImageView.animationDuration = animTime;
animatedImageView.animationRepeatCount = 1;
[self.view addSubview: animatedImageView];
[animatedImageView startAnimating];
答案 3 :(得分:0)
你可以应用CGAffineTransformMakeTranslation,如果你想要的只是一条简单的移动整个画面的整个鸟在一行。
类似的东西:
[UIView animateWithDuration:1.0 animations:^{
// move bird as a whole, 300 units across the screen
self.animationImageView.transform = CGAffineTransformMakeTranslation(300,0);
}];