1. - (void)viewDidLoad {
  2. [super viewDidLoad];
  3. // Do any additional setup after loading the view.
  4.  
  5. /*********UIImage***********/
  6. //由名字直接读取图片
  7. //优点:用时相对较短
  8. //缺点:读取之后会占用内存
  9. //如果图片较小,用名字直接读取
  10.  
  11. UIImage *imageName = [UIImage imageNamed:@"1.png"];
  12.  
  13. //UIImageView
  14. UIImageView *imageViewName = [[UIImageView alloc] initWithFrame:CGRectMake(, , , )];
  15. imageViewName.image = imageName;
  16. [self.view addSubview:imageViewName];
  17.  
  18. //由图片的路径读取图片
  19. //优点:读取之后不会占用内存
  20. //缺点:用时相对较长
  21. //如果图片较大,用路径直接读取
  22.  
  23. //获取图片路径:相对路径
  24. //第一个参数:文件的名字
  25. //第二个参数:文件的类型
  26. NSString *path = [[NSBundle mainBundle] pathForResource:@"map" ofType:@"png"];
  27. UIImage *imagePath = [UIImage imageWithContentsOfFile:path];
  28. //UIImageView
  29. UIImageView *imageViewPath = [[UIImageView alloc] initWithFrame:CGRectMake(, , , )];
  30. imageViewPath.image = imagePath;
  31. [self.view addSubview:imageViewPath];
  32.  
  33. /**********UIImageView-动画效果*************/
  34. UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(, , , )];
  35. imageView.backgroundColor = [UIColor grayColor];
  36. imageView.image = [UIImage imageNamed:@"1.png"];
  37.  
  38. /****动画效果相关属性****/
  39. //创建图片数组
  40. //开辟内存空间
  41. NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:];
  42. for (int i = ; i <= ; i ++) {
  43. [array addObject:[UIImage imageNamed:[NSString stringWithFormat:@"player%d.png",i]]];
  44. }
  45.  
  46. //设置动画图片,需要接收一个数组,数组里面的类型必须是UIImage类型
  47. imageView.animationImages = array;
  48. //动画时间:数组里面所有的图片转一圈所用时间
  49. imageView.animationDuration = ;
  50. //循环次数:大于0的数:写几就循环几次,结束 0:无限循环
  51. imageView.animationRepeatCount = ;
  52.  
  53. //tag
  54. imageView.tag = ;
  55.  
  56. [self.view addSubview:imageView];
  57.  
  58. //开始动画
  59. [imageView startAnimating];
  60.  
  61. //UIButton
  62. UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
  63. button.frame = CGRectMake(, , , );
  64. button.backgroundColor = [UIColor redColor];
  65. [button setTitle:@"button" forState:UIControlStateNormal];
  66. [button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
  67. [self.view addSubview:button];
  68. }
  69. #pragma mark - 按钮的点击事件:停止或开始动画
  70. - (void)buttonClick:(UIButton *)button{
  71. //找到UIImageView
  72. UIImageView *imageView = (UIImageView *)[self.view viewWithTag:];
  73. //停止动画
  74. // [imageView stopAnimating];
  75.  
  76. static BOOL isAnimation = YES;
  77. if (isAnimation) {
  78. [imageView stopAnimating];
  79. isAnimation = NO;
  80. }else{
  81. [imageView startAnimating];
  82. isAnimation = YES;
  83. }
  84. }

//*********************************************

  1. //时间
  2. //第一个参数执行动作相隔的时间
  3. //第二个参数通知给谁:self
  4. //第三个参数:执行的相关方法
  5. //第四个参数:nil
  6. //第五个参数:是否重复执行 YES:重复 NO:不重复
  7. // [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(timer:) userInfo:nil repeats:YES];
  8.  
  9. //self.view.bounds 以(0, 0)点为起点,全屏大小的view
  10. UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.view.bounds];
  11. imageView.image = [UIImage imageNamed:@"back2.jpg"];
  12. [self.view addSubview:imageView];
  13.  
  14. //动画效果的UIImageView
  15. UIImageView *birdView = [[UIImageView alloc] initWithFrame:CGRectMake(, , 60.5, )];
  16. //tag
  17. birdView.tag = ;
  18.  
  19. //图片数组
  20. NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:];
  21. for (int i = ; i <= ; i ++) {
  22. [array addObject:[UIImage imageNamed:[NSString stringWithFormat:@"DOVE%d.png",i]]];
  23. }
  24.  
  25. /**UIImageView的动画属性***/
  26. birdView.animationImages = array;
  27. birdView.animationDuration = ;
  28. birdView.animationRepeatCount = ;
  29. //开始动画
  30. [birdView startAnimating];
  31.  
  32. [imageView addSubview:birdView];
  33.  
  34. //控制bird位置
  35. [NSTimer scheduledTimerWithTimeInterval: target:self selector:@selector(changeFrame:) userInfo:nil repeats:YES];
  36. }
  37. #pragma mark - 改变bird的位置
  38. - (void)changeFrame:(NSTimer *)timer{
  39. UIImageView *imageView = (UIImageView *)[self.view viewWithTag:];
  40. static int i = ;
  41. [UIView animateWithDuration: animations:^{
  42. imageView.frame = CGRectMake( + (i++ * ), +arc4random()%, 60.5, );
  43. }];
  44. if ( +(i++ * ) > ) {
  45. imageView.frame = CGRectMake(, , 60.5, );
  46. i = ;
  47. }
  48. }
  49. #pragma mark - NSTimer的事件
  50. - (void)timer:(NSTimer *)timer{
  51. NSLog(@"timer");
  52. }
  53. #pragma mark - 按钮的点击事件
  54. - (void)buttonClick:(UIButton *)button{
  55. //UIView的动画效果
  56. //第一个参数:动画执行的时间
  57. //第二个参数:执行动作
  58. // [UIView animateWithDuration:3 animations:^{
  59. // self.view.backgroundColor = [UIColor colorWithRed:arc4random()%256/255.0 green:arc4random()%256/255.0 blue:arc4random()%256/255.0 alpha:1.0];
  60. // }];
  61.  
  62. //第一个参数:动画执行的时间
  63. //第二个参数:动画延迟执行的时间
  64. //第三个参数:动画执行的效果
  65. //第四个参数:执行动作
  66. //第五个参数:执行完要做的动作之后做的操作
  67. [UIView animateWithDuration: delay: options:UIViewAnimationOptionOverrideInheritedOptions animations:^{
  68. self.view.backgroundColor = [UIColor colorWithRed:arc4random()%/255.0 green:arc4random()%/255.0 blue:arc4random()%/255.0 alpha:1.0];
  69. } completion:^(BOOL finished) {
  70. // self.view.backgroundColor = [UIColor orangeColor];
  71. }];
  72. }

UIImageView的更多相关文章

  1. AFNetworking 3.0 源码解读(十)之 UIActivityIndicatorView/UIRefreshControl/UIImageView + AFNetworking

    我们应该看到过很多类似这样的例子:某个控件拥有加载网络图片的能力.但这究竟是怎么做到的呢?看完这篇文章就明白了. 前言 这篇我们会介绍 AFNetworking 中的3个UIKit中的分类.UIAct ...

  2. 6. UIImageView 的使用

    1. UIImageView 的认识 QQ:853740091 UIImageView 继承UIView,通过他的名字我们也可以看出这个是用来显示图片的 2. 使用方法 UIImageView *im ...

  3. UI控件(UIImageView)

    @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; image1_ = [UIImage imageNa ...

  4. iOS--使用UIImageView进行GIF动图播放

    大家好,好久没有跟新了.其实也就昨天到今天的时间. 前言:实际上,GIF动图文件中包含了一组图片及其信息数组,这些信息数据记录着这一组图片中各张图片的播放时长等信息,我们可以将图片和这些信息或取出来, ...

  5. UIImageView 自带动画+N张图片实现很炫的动画

    gitHub上又看到个很炫的动画:https://github.com/MartinRGB/GiftCard-iOS   看了看他的代码,发现核心动画(就是把按钮包装成一个礼物盒)其实很简单,就是把一 ...

  6. IOS开发之Bug--关于UIImageView的使用

    这里是遇到的一个关于使用UIImageView的小bug,bug就是加载不出来图片. 原因:如果图片资源是jpg文件,如果代码没有加后缀.jpg就会出现不加载出来的情况: 添加上.jpg就能加载出来了 ...

  7. UIScrollView,UIPageControl,UIImageView 实现图片轮播的效果

    上一篇博客介绍了如何将XCode创立的项目提交到Git版本控制,这次就直接做一个图片轮播的展示demo,刚好可以把UIScrollView.UIPageControl.UIImageView这三个控件 ...

  8. iOS中UIImageView的填充模式

    UIImageView的填充模式 属性名称 imageV.contentMode枚举属性: @"UIViewContentModeScaleToFill", // 拉伸自适应填满整 ...

  9. NSBundle控件和UIImageView和UIButton区别

    1.NSBundle 1> 一个NSBundle代表一个文件夹,利用NSBundle能访问对应的文件夹 2> 利用mainBundle就可以访问软件资源包中的任何资源 3> 模拟器应 ...

随机推荐

  1. SubSonic3.0.0.4.3源码包与调用Dll

    版本修改历史 3.0.0.4.3版修复了下面问题: 修正多表关联查询时,使用左关联和右关联出错问题修正DbDataProvider.cs类的ToEnumerable函数打开数据库链接后没有关闭的问题添 ...

  2. Objective-C中的内存管理

    在编程语言中是少不了对内存的管理的,内存对于计算机来说是宝贵的资源,所以对使用不到的资源进行回收是很有必要的.OC中使用引用计数和垃圾回收来管理内存,在OC中为每个对象分配一个引用计数器,当对象刚刚被 ...

  3. 相克军_Oracle体系_随堂笔记010-SCN

    1.SCN的意义?system change number     时间    先后.新旧 select dbms_flashback.get_system_change_number, SCN_TO ...

  4. HP-UX 11g RAC安装 记录

    环境:HP-UX 11.31 + GI 11.2.0.4 + Oracle 11.2.0.4 背景:本文只对HP-UX平台安装11g RAC环境过程中,针对一些跟Linux平台有差异的地方进行简单记录 ...

  5. 几个步骤轻松搞定ASP.NET 依赖注入。

    http://www.it165.net/pro/html/201407/17685.html 我在网上看到了这篇文章,这边文章主要说的方法就是通过读取配置文件来解决依赖注入的问题.但是每次新建一个依 ...

  6. 汽车之家一道SQL 面试题,大家闲来无事都来敲一敲

    写在前面 上周去汽车之家面试,拿到这个SQL笔试题顿时感觉到有些陌生,因为好长时间不写SQL语句了,当时只写了表设计,示例数据和SQL语句都没写出来. 汽车之家应该用的SQL Server, 编程题一 ...

  7. java中List对象列表去重或取出以及排序

    面试碰到几次list的去重和排序.下面介绍一种做法: 1. list去重 1.1 实体类Student List<Student>容量10k以上,要求去重复.这里Student的重复标准是 ...

  8. 初来乍到 Java 和 .Net 迭代器功能

    最近有一个需求是这样的, 根据键值对存储类型数据,也算是数据缓存块模块功能设计. 一个键对应多个值.每一个键的值类型相同,但是每个不同的键之间类型不一定相同. Java 设计如下 HashMap< ...

  9. jQuery图片轮播特效

    效果预览:http://hovertree.com/texiao/jquery/51/ 这款特效有缩略图,包含文字说明和链接,可以自动播放,也可以手动切换. 使用的jQuery库版本为1.12.3 , ...

  10. 【开源】SoDiaoEditor 可能是目前最好用的开源电子病历编辑器(B/S架构)

    此刻我的内心是忐忑的,这个标题给了我很大的压力,虽然很久以前我就在github上搜索一圈了,也没发现有其他更好的开源电子病历编辑器,如各位亲发现有更好的,烦请知会我一声. 该编辑器其实已经憋了很久了, ...