1. //
  2. // ViewController.m
  3. // UI4_UIImageView
  4. //
  5. // Created by zhangxueming on 15/7/1.
  6. // Copyright (c) 2015年 zhangxueming. All rights reserved.
  7. //
  8.  
  9. #import "ViewController.h"
  10.  
  11. @interface ViewController ()
  12.  
  13. @end
  14.  
  15. @implementation ViewController
  16.  
  17. - (void)viewDidLoad {
  18. [super viewDidLoad];
  19. // Do any additional setup after loading the view, typically from a nib.
  20. //ImageView --- 显示图片
  21.  
  22. NSString *path =[[NSBundle mainBundle] pathForResource:@"map" ofType:@"png"];
  23. //NSLog(@"path = %@", path);
  24.  
  25. //加载图片,通常加载大图片,效率低一点
  26. UIImage *image = [UIImage imageWithContentsOfFile:path];
  27.  
  28. UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
  29. imageView.frame =CGRectMake(10, 100, self.view.frame.size.width-20, 400);
  30. [self.view addSubview:imageView];
  31.  
  32. //添加手势
  33. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapImageView)];
  34. //设置点击次数
  35. tap.numberOfTapsRequired = 1;
  36. //设置触摸点个数
  37. tap.numberOfTouchesRequired = 1;
  38. //使能imageView用户交互
  39. imageView.userInteractionEnabled =YES;
  40. //添加手势到imageView上
  41. [imageView addGestureRecognizer:tap];
  42.  
  43. NSMutableArray *imageArray = [NSMutableArray array];
  44. for (int i=0; i<12; i++) {
  45. NSString *imageName = [NSString stringWithFormat:@"player%d",i+1];
  46. UIImage *image = [UIImage imageNamed:imageName];
  47. [imageArray addObject:image];
  48. }
  49.  
  50. UIImageView *aniImageView = [[UIImageView alloc] initWithFrame:CGRectMake(150, 200, 100, 100)];
  51. aniImageView.tag = 100;
  52. aniImageView.animationImages =imageArray;
  53. //
  54. [self.view addSubview:aniImageView];
  55.  
  56. //设置动画播放时间
  57. aniImageView.animationDuration = 2.0;
  58. //开始播放动画
  59. [aniImageView startAnimating];
  60.  
  61. }
  62.  
  63. - (void)tapImageView
  64. {
  65. NSLog(@"imageView 被点击");
  66. static BOOL aniState = YES;
  67. UIImageView *imageView = (UIImageView *)[self.view viewWithTag:100];
  68. if (aniState) {
  69. [imageView stopAnimating];
  70. aniState = NO;
  71. }
  72. else
  73. {
  74. [imageView startAnimating];
  75. aniState = YES;
  76. }
  77. }
  78.  
  79. - (void)didReceiveMemoryWarning {
  80. [super didReceiveMemoryWarning];
  81. // Dispose of any resources that can be recreated.
  82. }
  83.  
  84. @end

UI4_UIImageView的更多相关文章

随机推荐

  1. GridView编辑删除操作

    第一种:使用DataSource数据源中自带的编辑删除方法,这样的不经常使用,在这里就不加说明了. 另外一种:使用GridView的三种事件:GridView1_RowEditing(编辑).Grid ...

  2. linux man使用方法 和centos安装中文man包 --转

    http://blog.chinaunix.net/uid-25100840-id-302308.html 这两天学习<linux设备驱动程序开发详解>中的异步通知,其中有一个fcntl( ...

  3. SimpleUrlHandlerMapping 处理器映射的配置--转

    http://blog.csdn.net/rainier001/article/details/6860491 <?xml version="1.0" encoding=&q ...

  4. The Socket API, Part 5: SCTP

    转:http://www.linuxforu.com/2011/12/socket-api-part-5-sctp/ By Pankaj Tanwar on December 29, 2011 in  ...

  5. javascript函数中的实例对象、类对象、局部变量(局部函数)

    定义 function Person(national,age) { this.age = age; //实例对象,每个示例不同 Person.national = national; //类对象,所 ...

  6. iso8583报文自学笔记

    一.8583报文组成 TPDU 报文头 应用数据 ISO8583 Msg ID 目的 地址 源地址 应用类别定义 软件 总版本号 终端 状态 处理 要求 保留使用(软件分版本号) 交易数据 60H N ...

  7. Wamp,XAMPP 无法启动,端口未占用的故障处理

    打开服务管理里:Service.msc 找到服务:WinHttpAutoProxySvc(WinHTTP 实现了客户端 HTTP 堆栈并向开发人员提供 Win32 API 和 COM 自动化组件以供发 ...

  8. 自动备份并保存最近几天的SQL数据库作业脚本

    DECLARE @filename VARCHAR(255) DECLARE @date DATETIME SELECT @date=GETDATE() SELECT @filename = 'G:\ ...

  9. C语言中的命名空间

    C语言中的命名空间 命名空间是为了解决 "在相同作用域内如何区分 相同的标识符". 说明: ①只有在相同作用域的情况下才能使用到命名空间去区分标识符,在嵌套的作用域.不同的作用域区 ...

  10. String类的方法2

    ---恢复内容开始--- .ToLower()    //转为小写字符串"AbC"-->"abc" .ToUpper()    //转为大写"A ...