// 定义按钮,图片控件、可变数组对象 UIButton *actionbuttom; UIImageView *imageMove; NSMutableArray *imgsarray;
// image动画
// 初始化UIImageView,大小和View的大小相同
imageMove = [[UIImageView alloc]initWithFrame:self.view.frame];
// 设置UIImageView的初始化图片
imageMove.image = [UIImage imageNamed:@"cat_eat0000.jpg"];
// 把UIImageView加载到页面
[self.view addSubview:imageMove];
// 设置UIImageView的交互性为yes
imageMove.userInteractionEnabled = YES;
// 创建功能按钮
// 初始化按钮
actionbuttom = [[UIButton alloc]initWithFrame:CGRectMake(100, 680, 218, 50)];
// 设置按钮背景色
actionbuttom.backgroundColor = [UIColor yellowColor];
// 设置按钮标题
[actionbuttom setTitle:@"开始播放" forState:UIControlStateNormal];
// 设置按钮文字颜色
[actionbuttom setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
// 为按钮添加触发事件
[actionbuttom addTarget:self action:@selector(startmove:) forControlEvents:UIControlEventTouchUpInside];
// 把按钮添加到页面中
[imageMove addSubview:actionbuttom];
// 初始化可变数组,用来存放图片
imgsarray = [[NSMutableArray alloc]initWithCapacity:40];
// 循环从资源中拿到四十张图片,并添加到imgsarray。
for (int x=0; x<40; x++) {
NSString *imgname = [NSString stringWithFormat:@"cat_eat00%.2d.jpg",x];
UIImage *img = [UIImage imageNamed:imgname];
[imgsarray addObject:img];
//按钮的触发事件
-(void)startmove:(id)sender{
// 设置动画时长
imageMove.animationDuration = 2;
// 设置动画图片来源为图片数组
imageMove.animationImages = imgsarray;
// 设置动画重复次数,0是无限循环,1为重复1次
imageMove.animationRepeatCount = 1;
// 开始播放
[imageMove startAnimating];
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有