【问题标题】:Object-c How to animate different set of images in different duration time one after the other (iphone)Object-c 如何在不同的持续时间内为不同的图像集设置动画(iphone)
【发布时间】:2011-12-21 03:53:16
【问题描述】:

我需要一个接一个地为 10 组图像(10 组图像)制作动画 每组将在不同的持续时间内进行动画处理。 我试图用这样的 UIImageView 做到这一点:

[myImageView1 setAnimationImages:imagesSet1];
[myImageView1 setAnimationRepeatCount:0];
[myImageView1 setAnimationDuration:2];
[myImageView1 startAnimation];


[myImageView1 setAnimationImages:imagesSet2];
[myImageView1 setAnimationRepeatCount:0];
[myImageView1 setAnimationDuration:5];
[myImageView1 startAnimation];

但这不起作用,它显示最后的图像。

【问题讨论】:

  • 因为你不断调用 Animations ,这就是问题

标签: iphone animation uiimageview uiimage core-animation


【解决方案1】:

试试这个代码,更简单,所以用它享受吧

animatedImageView = [[UIImageView alloc] initWithFrame:self.view.bounds];

animatedImageView.animationImages = [NSArray arrayWithObjects:
                                     [UIImage imageNamed:@"1.png"],
                                     [UIImage imageNamed:@"2.png"],
                                     [UIImage imageNamed:@"3.png"],
                                     [UIImage imageNamed:@"4.png"],
                                     [UIImage imageNamed:@"5.png"],
                                     [UIImage imageNamed:@"6.png"],nil];
animatedImageView.animationDuration = 20.0f;
animatedImageView.animationRepeatCount = 0;
[animatedImageView startAnimating];

【讨论】:

  • 它永远不会停止。如何阻止它?我设置了重复计数,但结果没有改变。
  • @yucelbayram:请设置[animatedImageView stopAnimating];当您需要停止时。
【解决方案2】:

试试这个代码:

 NSArray *array1=[[NSArray alloc] initWithObjects:[UIImage imageNamed:@"ballImg1.png"],[UIImage imageNamed:@"ballImg3.png"],[UIImage imageNamed:@"ballImg4.png"],[UIImage imageNamed:@"ballImg5.png"],nil];

 NSArray *array2=[[NSArray alloc] initWithObjects:[UIImage imageNamed:@"ballAniImg1.png"],[UIImage imageNamed:@"ballAniImg3.png"],[UIImage imageNamed:@"ballAniImg4.png"],[UIImage imageNamed:@"ballAniImg5.png"],nil];

 NSArray *array3=[[NSArray alloc] initWithObjects:[UIImage imageNamed:@"ballRotImg1.png"],[UIImage imageNamed:@"ballRotImg3.png"],[UIImage imageNamed:@"ballRotImg4.png"],[UIImage imageNamed:@"ballRotImg5.png"],nil];

array4=[[NSArray alloc] initWithObjects:array1,array2,array3,nil];

 i1=0;   
 [self performSelector:@selector(animation1:) withObject:[NSNumber numberWithFloat:2.0] afterDelay:0];
 i=0;



 -(void)animation1:(NSNumber*)k
{
if(i1<[array4 count])
{
int m1=[k floatValue];
NSArray *arr1= [array4 objectAtIndex:i1];
myImageView1.animationImages=arr1;
myImageView1.animationDuration=m1;
myImageView1.animationRepeatCount=1;
[myImageView1 startAnimating];
i1++;
    [self performSelector:@selector(animation1:) withObject:[NSNumber numberWithFloat:2.0] afterDelay:3.0];

}
}

【讨论】:

    【解决方案3】:
        NSMutableArray *imageArray = [[NSMutableArray alloc] init];
    
        for (int i = 0; i < 6; i++)
        {
            [imageArray addObject:[UIImage imageNamed:[NSString stringWithFormat:@"ball%d.png", i]]];
            UIImageView *animatedImages = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,100,100)];
            animatedImages.animationImages = [NSArray arrayWithArray:imageArray];
            animatedImages.animationDuration = 1.0;
            animatedImages.animationRepeatCount = 0;
            [animatedImages startAnimating];
            [myview addSubview:animatedImages];  
            [animatedImages release];
    
         }
    

    【讨论】:

    • 但我想在不同的时间一个接一个地运行一组图像!?
    • 如果你想运行三个图像只需将名称保存为 ball1.png 、 ball2.png 、 ball3.png ...此代码将起作用...
    • 但是我怎样才能改变每个动画图像组的动画图像.animationDuration?
    • 不要更改此代码的任何内容...只需更改图像名称...它会很好地工作...
    【解决方案4】:

    尝试使用方块

    -(void)showImage1 {
        [UIView animateWithDuration:2.0
                              delay:0.0 
                            options:UIViewAnimationOptionTransitionFlipFromLeft 
                         animations:^{
                                         [myImageView1 setImage:image1];
                                     };
                         completion:^(BOOL finished){
                                           [self showImage2];
                                    }];
    }
    
    -(void)showImage2 {
        [UIView animateWithDuration:5.0
                              delay:0.0 
                            options:UIViewAnimationOptionTransitionFlipFromLeft 
                         animations:^{
                                         [myImageView1 setImage:image2];
                                     };
                         completion:^(BOOL finished){
                                           ...
                                    }];
    }
    

    【讨论】:

    • 奇怪的是我没有“UIViewAnimationOptionTransitionFlipFromLeft”选项?!
    • UIViewAnimationOptionTransitionFlipFromLeft 围绕垂直轴从左到右翻转视图的过渡。视图的左侧向前方移动,右侧向后方移动。在 iOS 4.0 及更高版本中可用。在 UIView.h 中声明。来自developer.apple.com/library/ios/#documentation/uikit/reference/…
    • 好的,我改用“UIViewAnimationTransitionFlipFromRight”,但什么也没发生,
    • 我该如何解决这个问题?,我完全按照你说的做了,但还是不行
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-11-17
    • 1970-01-01
    • 2011-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多