//在根视图控制器里创建图片视图
UIImageView*imgView=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 293, 220)];
imgView.backgroundColor=[UIColor cyanColor];
imgView.center=CGPointMake(160, 240);
//动态图里有四张静态图
for (int i=0; i<4; i++) {
NSString*imageName=[NSString stringWithFormat:@"1234.%d.tiff",i+1];
UIImage*image=[UIImage imageNamed:imageName];
[images addObject:image];
}
imgView.animationImages=images;//给imgView指定一组用于做动画的图片
imgView.animationDuration=1;//动画的总时长
[imgView startAnimating];//让动态图开始动起来
imgView.tag=100;//设tag值便于方法里面调用
[self.view addSubview:imgView];
[imgView release];
//创建控制UISlider
UISlider *slider=[[UISlider alloc]initWithFrame:CGRectMake(14, 360, 293, 20)];
slider.backgroundColor=[UIColor cyanColor];
slider.minimumValue=0.0;
slider.maximumValue=5;
slider.value=5;
[slider addTarget:self action:@selector(updateValue:) forControlEvents:UIControlEventValueChanged];//设置响应事件
[self.view addSubview:slider];
[slider release];
// Do any additional setup after loading the view.
}
-(void)updateValue:(UISlider*)slider{
UIImageView *img=(UIImageView*)[self.view viewWithTag:100];
NSLog(@"-----%f",slider.value);//打印slider的值
img.animationDuration=(NSTimeInterval)slider.value;
[img startAnimating];
}