我想在UIImageView上应用动画(通过UIBuilder创建)



我添加了一个UIView,在那个UIImageView上使用UIBuider,现在我想在该imageView上应用动画,所以我拍摄了一系列图像并添加它数组到图像查看此代码

 NSArray *animationArray=[[NSArray alloc]init];
        animationArray=[NSArray arrayWithObjects:
                        [UIImage imageNamed:@"rabbit1.png"],
                        [UIImage imageNamed:@"rabbit2.png"],
                        [UIImage imageNamed:@"rabbit3.png"],
                        [UIImage imageNamed:@"rabbit4.png"],
                        [UIImage imageNamed:@"rabbit5.png"],
                        [UIImage imageNamed:@"rabbit6.png"],
                        [UIImage imageNamed:@"rabbit7.png"],
                        [UIImage imageNamed:@"rabbit8.png"],
                        [UIImage imageNamed:@"rabbit9.png"],
                        [UIImage imageNamed:@"rabbit10.png"],
                        [UIImage imageNamed:@"rabbit11.png"],
                        [UIImage imageNamed:@"rabbit12.png"],
                        [UIImage imageNamed:@"rabbit13.png"], nil];

        tempImageView.animationImages=animationArray;
        tempImageView.animationDuration=2;
        tempImageView.animationRepeatCount=0;
        [tempImageView startAnimating];

tempImageView 是使用 UIBuider 创建的但它没有醒来,没有显示任何东西。

故事板自动布局中似乎有一个错误。我发现同样没有结果..

通过代码尝试一下,这行得通。

mainImageView = [[UIImageView alloc]init];
    NSArray *animationArray = [[NSArray alloc]init];
    animationArray = [NSArray arrayWithObjects:[UIImage imageNamed:@"first.png"],[UIImage imageNamed:@"second.png"],[UIImage imageNamed:@"first.png"],[UIImage imageNamed:@"second.png"],[UIImage imageNamed:@"first.png"],[UIImage imageNamed:@"second.png"],[UIImage imageNamed:@"first.png"],[UIImage imageNamed:@"second.png"],[UIImage imageNamed:@"first.png"],[UIImage imageNamed:@"second.png"], nil]; //add your images here
    [mainImageView  setFrame:CGRectMake(50,50,100,100)];
    mainImageView.animationImages = animationArray; //mainImageView is   imageview
    mainImageView.animationDuration = 2;
    mainImageView.animationRepeatCount = 0;
    [mainImageView startAnimating];

      [self.view addSubview:mainImageView];

最新更新