当前位置: 移动技术网 > 移动技术>移动开发>IOS > IOS UI学习教程之使用UIImageView控件制作动画

IOS UI学习教程之使用UIImageView控件制作动画

2019年07月24日  | 移动技术网移动技术  | 我要评论

本文实例为大家分享了ios使用uiimageview控件制作动画的方法,供大家参考,具体内容如下

先添加40张tomcat的图片到资源列表中:名称为cat_eat0000.jpg到cat_eat0039.jpg。
1、定义所需控件

//  定义按钮,图片控件、可变数组对象
  uibutton *actionbuttom;
  uiimageview *imagemove;
  nsmutablearray *imgsarray;

2、初始化各控件

//  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];

3、设置按钮触发动画播放

//按钮的触发事件
-(void)startmove:(id)sender{
//  设置动画时长
  imagemove.animationduration = 2;
//  设置动画图片来源为图片数组
  imagemove.animationimages = imgsarray;
//  设置动画重复次数,0是无限循环,1为重复1次
  imagemove.animationrepeatcount = 1;
//  开始播放
  [imagemove startanimating];
  
}

以上就是本文的全部内容,希望对大家学习使用uiimageview控件制作动画有所帮助。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网