如何在ios中制作背景动画时为图片制作动画?

时间:2014-08-07 06:02:02

标签: ios

我是一个尝试制作ios游戏的新手。我想为视图的背景设置动画,同时在视图上设置另一个图像的动画。我该怎么做呢如果我太模糊,请原谅我。

2 个答案:

答案 0 :(得分:1)

您可以使用imageview为图像添加动画效果。下面的代码是一个例子。它是一个简单的动画

  NSArray *imageNames = @[@"win_1.png", @"win_2.png", @"win_3.png", @"win_4.png",
                    @"win_5.png", @"win_6.png", @"win_7.png", @"win_8.png",
                    @"win_9.png", @"win_10.png", @"win_11.png", @"win_12.png",
                    @"win_13.png", @"win_14.png", @"win_15.png", @"win_16.png"];

NSMutableArray *images = [[NSMutableArray alloc] init];
for (int i = 0; i < imageNames.count; i++) {
    [images addObject:[UIImage imageNamed:[imageNames objectAtIndex:i]]];
}

// Normal Animation
UIImageView *animationImageView = [[UIImageView alloc] initWithFrame:CGRectMake(60, 95, 86, 193)];
animationImageView.animationImages = images;
animationImageView.animationDuration = 0.5;

[self.view addSubview:animationImageView];
[animationImageView startAnimating];

// Slow motion animation
UIImageView *slowAnimationImageView = [[UIImageView alloc] initWithFrame:CGRectMake(160, 95, 86, 193)];
slowAnimationImageView.animationImages = images;
slowAnimationImageView.animationDuration = 5;

[self.view addSubview:slowAnimationImageView];
[slowAnimationImageView startAnimating];

答案 1 :(得分:0)

[UIView animateWithDuration:2.0 delay:0.0 options:UIViewAnimationOptionCurveLinear
                             animations:^{
                                 [imageView setImage:[UIImage imageNamed:@"imageview image1"]];
                                 mainView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"view background imageName1.png"]];
                             }
                             completion:^(BOOL finished) {
                             [imageView setImage:[UIImage imageNamed:@"imageview image2"]];
                                 mainView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"view background imageName2"]];
}];