1、UIImageView 动画

  • 1.1 播放图片集

    @property (nonatomic, strong) UIImageView *playImageView;
    
    self.playImageView = [[UIImageView alloc] initWithFrame:self.view.bounds];
    [self.view addSubview:self.playImageView]; // 创建图片集
    NSMutableArray *imageArray = [NSMutableArray arrayWithCapacity:0]; for (int i = 1; i < 30; i++) { // 添加图片
    [imageArray addObject:[UIImage imageNamed:[NSString stringWithFormat:@"%d.jpg", i]]];
    } // 播放图片集
    self.playImageView.animationImages = imageArray; // 设置播放的图片集(需将图片添加到数组 imageArray 中)
    self.playImageView.animationDuration = 29; // 设置播放整个图片集的时间
    self.playImageView.animationRepeatCount = 0; // 设置循环播放次数,默认为 0 一直循环
    [self.playImageView startAnimating]; // 开始播放 // [self.playImageView stopAnimating]; // 停止播放动画
    • 效果

  • 1.2 汤姆猫

    #import <AudioToolbox/AudioToolbox.h>
    
    @property (nonatomic, strong) UIImageView *playImageView;
    
    // 创建播放视图
    self.playImageView = [[UIImageView alloc] initWithFrame:self.view.bounds];
    self.playImageView.image = [UIImage imageNamed:@"background.jpg"];
    [self.view addSubview:self.playImageView]; // 创建功能按钮
    const CGFloat viewWith = self.view.bounds.size.width;
    const CGFloat viewHeight = self.view.bounds.size.height; const CGFloat gap = 10;
    const CGFloat buttonWith = self.view.bounds.size.width / 5;
    const CGFloat buttonHeight = buttonWith; // 功能按钮图片集
    NSArray *buttonImageNameArray = @[@"fart.png", @"cymbal.png", @"drink.png", @"eat.png", @"pie.png", @"scratch.png"]; for (int i = 0; i < 11; i++) { UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.playImageView addSubview:button]; self.playImageView.userInteractionEnabled = YES; if (i < 6) { // 两边功能按钮的布局 if (i < 3) { button.frame = CGRectMake(gap, viewHeight / 2 + (buttonHeight + gap ) * (i % 3), buttonWith, buttonHeight);
    }
    else { button.frame = CGRectMake(viewWith - buttonWith - gap, viewHeight / 2 + (buttonHeight + gap) * (i % 3), buttonWith, buttonHeight);
    } [button setBackgroundImage:[UIImage imageNamed:buttonImageNameArray[i]] forState:UIControlStateNormal]; } else { // 隐藏按钮的布局 if (i == 6){ // 头 button.frame = CGRectMake(viewWith/4, viewHeight/5, viewWith/2, viewHeight/4);
    }
    else if (i == 7){ // 肚子 button.frame = CGRectMake(viewWith/3, viewHeight/3*2, viewWith/3, viewHeight/7);
    }
    else if (i == 8){ // 左脚 button.frame = CGRectMake(viewWith/4*2, viewHeight/6*5, viewWith/6, viewHeight/7);
    }
    else if (i == 9){ // 右脚 button.frame = CGRectMake(viewWith/4, viewHeight/6*5, viewWith/5, viewHeight/7);
    }
    else{ // 尾巴 button.frame = CGRectMake(viewWith/9*6, viewHeight/7*5, viewWith/7, viewHeight/5);
    } // button.backgroundColor = [UIColor yellowColor];
    } button.tag = 100 + i; // 设置按钮事件
    [button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
    } /********************** 点击按钮事件处理 ************************************/
    - (void)buttonClick:(UIButton *)button { switch (button.tag - 100) { case 0: // fart 放屁 [self playAnimation:@"fart"];
    [self performSelector:@selector(playVoice:) withObject:@"fart" afterDelay:0.5]; break; case 1: // cymbal 敲锣 [self playAnimation:@"cymbal"];
    [self performSelector:@selector(playVoice:) withObject:@"cymbal" afterDelay:0.5]; break; case 2: // drink 喝牛奶 [self playAnimation:@"drink"];
    [self performSelector:@selector(playVoice:) withObject:@"drink" afterDelay:0.5]; break; case 3: // eat 吃小鸟 [self playAnimation:@"eat"];
    [self performSelector:@selector(playVoice:) withObject:@"eat" afterDelay:0.5]; break; case 4: // pie 撇东西 [self playAnimation:@"pie"];
    [self performSelector:@selector(playVoice:) withObject:@"pie" afterDelay:0.5]; break; case 5: // scratch 抓屏幕 [self playAnimation:@"scratch"];
    [self performSelector:@selector(playVoice:) withObject:@"scratch" afterDelay:1.5]; break; case 6: // knockout 头 [self playAnimation:@"knockout"];
    [self performSelector:@selector(playVoice:) withObject:@"knockout" afterDelay:0.5]; break; case 7: // stomach 肚子 [self playAnimation:@"stomach"];
    [self performSelector:@selector(playVoice:) withObject:@"stomach" afterDelay:0.5]; break; case 8: // foot_left 左脚 [self playAnimation:@"foot_left"];
    [self performSelector:@selector(playVoice:) withObject:@"foot_left" afterDelay:0.5]; break; case 9: // foot_right 右脚 [self playAnimation:@"foot_right"];
    [self performSelector:@selector(playVoice:) withObject:@"foot_right" afterDelay:0.5]; break; case 10: // angry 尾巴 [self playAnimation:@"angry"];
    [self performSelector:@selector(playVoice:) withObject:@"angry" afterDelay:0.8]; break; default:
    break;
    }
    } /********************** 播放动画 ************************************/
    - (void)playAnimation:(NSString *)key { // 读取 plist 文件获取图片数量
    NSDictionary *imageNumDictionary = [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"TomCat" ofType:@"plist"]]; int imageNum = [[imageNumDictionary objectForKey:key] intValue]; NSMutableArray *imageArray = [NSMutableArray arrayWithCapacity:0]; for (int i = 0; i < imageNum; i++) { [imageArray addObject:[UIImage imageNamed:[NSString stringWithFormat:@"%@_%.2d.jpg", key, i]]];
    } self.playImageView.animationImages = imageArray;
    self.playImageView.animationDuration = imageNum/13;
    self.playImageView.animationRepeatCount = 1; [self.playImageView startAnimating]; // 播放动画
    } /********************** 播放声音 ************************************/
    - (void)playVoice:(NSString *)key { // 添加声音
    SystemSoundID soundID;
    AudioServicesCreateSystemSoundID((__bridge CFURLRef)([NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:key ofType:@"wav"]]), &soundID); AudioServicesPlayAlertSound(soundID); // 播放声音
    }
    • 效果

      ------

UIImageView 动画的更多相关文章

  1. iOS - UIImageView 动画

    1.UIImageView 动画 1.1 播放图片集 播放图片集 @property (nonatomic, strong) UIImageView *playImageView; self.play ...

  2. UIImageView 动画 / UIImage 方向

    UIImage 方向 UIImage imageOrientation是相对当前屏幕的横竖屏来判断方向 如果本身是横屏, 照片也是横屏的话, 方向是正方向 BOOL b1 = (originalIma ...

  3. UIImageView动画制作

    1.先初始化一个UIImageView的视图窗口 如:anima UIImageView *anima = [UIImageView alloc]initWithFrame(0,0,100,100); ...

  4. 通过cagradientLayer类封装uiimageview动画色度差

    #import <UIKit/UIKit.h> typedef NS_ENUM(NSInteger, EcolorDirectionType) { EcolorDirectionUp, / ...

  5. UIImageView~动画播放的内存优化

    我目前学到的知识,播放动画的步骤就是下面的几个步骤,把照片资源放到数组里面,通过动画animationImage加载数组,设置动画播放的 时间和次数完成播放. 后来通过看一些视频了解到:当需要播放多个 ...

  6. UIImageView动画

    NSMutableArray *arrM = [NSMutableArray array]; // 2.加载所有图片 ; i <= ; i++) { NSString *imageName = ...

  7. iOS - Core Animation 核心动画

    1.UIView 动画 具体讲解见 iOS - UIView 动画 2.UIImageView 动画 具体讲解见 iOS - UIImageView 动画 3.CADisplayLink 定时器 具体 ...

  8. 【IOS 开发】基本 UI 控件详解 (UISegmentedControl | UIImageView | UIProgressView | UISlider | UIAlertView )

    转载请注明出处 : http://blog.csdn.net/shulianghan/article/details/50163725 一. 分段控件 (UISegmentedControl) 控件展 ...

  9. iOS常用技术

    1.判断系统 #define UMSYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersi ...

随机推荐

  1. Python内置函数二 (递归函数,匿名函数,二分法)

    匿名函数 lambda() 语法: lambad  参数 : 返回值 def func(a,b): return a * b print(func(2,5)) a = lambda a ,b : a* ...

  2. PHP框架 Laravel

    PHP框架 CI(CodeIgniter) http://www.codeigniter.com/ http://codeigniter.org.cn/ Laravel PHP Laravel htt ...

  3. ubuntu安装Docky 3.0

    添加PPA并在命令行安装,执行以下命令: sudo add-apt-repository ppa:ricotz/docky sudo apt-get update sudo apt-get insta ...

  4. OSCache-JSP页面缓存(1)

    一.OSCache提供的缓存标签 这是OSCache提供的标签库中最重要的一个标签,包括在标签中的内容将应用缓存机制进行处理,处理的方式将取决于编程者对cache标签属性的设置. 第一次请求到达时,标 ...

  5. 阿帕奇配置本地虚拟站点,XAMPP环境下

    首先利用XAMPP搭建的阿帕奇环境,必须得启动,不能启动的话www.baidu.com 在XAMPP的目录下的apache,打开httpd-vhosts.conf文件 E:\XAMPP\apache\ ...

  6. Python中sort与sorted函数

    python中列表的内置函数sort()可以对列表中的元素进行排序,而全局性的sorted()函数则对所有可迭代的序列都是适用的: 并且sort()函数是内置函数,会改变当前对象,而sorted()函 ...

  7. 【转】LVS/Nginx如何处理session问题

    原文地址:http://network.51cto.com/art/201005/200279.htm 通过设置persistence的值,使session会话保持. [51CTO.com独家特稿]业 ...

  8. Hadoop完全分别式环境搭建

    为学习大数据,需搭建Hadoop大数据环境,在此记录,以备以后查阅,同时分享出来,供需要者参考. 这里分几部分进行整理. 提纲: 一.说明和准备 二.设置免密登陆 分段网址:https://www.c ...

  9. C#实现访问网络共享文件夹

    C#实现访问网络共享文件夹,使用 WNetAddConnection2A 和 WNetCancelConnection2A. 在目标服务器建立共享文件夹,建立访问账号test; public enum ...

  10. PostgreSQL9.3+PostGIS2.1安装配置

    Postgresql——Postgresql是一种对象关系型数据库.下载地址:http://www.postgresql.org/download/ postgis (可选)——是一个空间数据库,它扩 ...