我想在图片视图上使用下面的代码,
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];
请告诉我哪里错了。 谢谢!
答案 0 :(得分:0)
您使用的以下代码应该可以使用。正如我所看到的,您正在创建一个已经拥有的imageView。使用.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];