简体   繁体   English

如何在视图控制器上的图像视图上使用动画

[英]How can I use Animation on Image View on View controller

I want to use below code on image view,我想在图像视图上使用以下代码,

NSArray *imageArray = [NSArray arrayWithObjects:

                       [UIImage imageNamed:@"tmp-0"],

                       [UIImage imageNamed:@"tmp-1"],

                       [UIImage imageNamed:@"tmp-2"],

                       [UIImage imageNamed:@"tmp-3"],

                       [UIImage imageNamed:@"tmp-4"],

                       [UIImage imageNamed:@"tmp-5"],

                       [UIImage imageNamed:@"tmp-6"],

                       [UIImage imageNamed:@"tmp-7"],nil];

UIButton *barButton = [UIButton buttonWithType:UIButtonTypeCustom];

[barButton setImage:[UIImage imageNamed:@"tmp-0"] 
forState:UIControlStateNormal]; // mine trick

[barButton.imageView setAnimationImages:imageArray];

[barButton.imageView setAnimationDuration:1.0f];


[barButton.imageView startAnimating];

[barButton sizeToFit];


self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:barButton];


Now I want to use this code on Image view, Please check

.m file

@property(nonatomic, strong) IBOutlet UIImageView *imageContactList;

@synthesize imageContactList;

- (void)viewDidLoad

{

 [super viewDidLoad];

 [self ContactListAnimated];

}

 UIImageView*animationView = [[UIImageView alloc] initWithFrame:self.view.frame];
    animationView.animationImages = 
                            [NSArray arrayWithObjects:

                            [UIImage imageNamed:@"1.gif"],

                            [UIImage imageNamed:@"2.gif"],

                            [UIImage imageNamed:@"3.gif"],

                            [UIImage imageNamed:@"4.gif"],

                            [UIImage imageNamed:@"5.gif"],

                            [UIImage imageNamed:@"6.gif"],nil];

    animationView.animationDuration = 1.25;

    animationView.animationRepeatCount = 0;

    [animationView startAnimating];

    [self.view addSubview:animationView];

Please tell me where I am wrong.请告诉我我错在哪里。 Thank you!谢谢!

The below code you used should work.您使用的以下代码应该可以工作。 As I see, you are creating an imageView where you already have one.如我所见,您正在创建一个已经拥有的 imageView。 Use the outlet you have in your .m file使用 .m 文件中的插座

NSArray *animationArray=[NSArray arrayWithObjects:
                                  [UIImage imageNamed:@"images.gif"],
                                      [UIImage imageNamed:@"images1.jpg"],
                                      [UIImage imageNamed:@"images2.jpg"],
                                   [UIImage imageNamed:@"images3.jpg"],
                    nil];

    //imageContactList is the UIImageView
    imageContactList.animationImages=animationArray;
    imageContactList.animationDuration=1.5;
imageContactList.animationRepeatCount=0;
    [imageContactList startAnimating]; 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM