- (void)viewDidLoad {[super viewDidLoad];// Do any additional setup after loading the view./*********UIImage***********///由名字直接读取图片//优点:用时相对较短//缺点:读取之后会占用内存//如果图片较小,用名字直接读取
    UIImage *imageName = [UIImage imageNamed:@"1.png"];//UIImageViewUIImageView *imageViewName = [[UIImageView alloc] initWithFrame:CGRectMake(20, 50, 60, 60)];imageViewName.image = imageName;[self.view addSubview:imageViewName];//由图片的路径读取图片//优点:读取之后不会占用内存//缺点:用时相对较长//如果图片较大,用路径直接读取//获取图片路径:相对路径//第一个参数:文件的名字//第二个参数:文件的类型NSString *path = [[NSBundle mainBundle] pathForResource:@"map" ofType:@"png"];UIImage *imagePath = [UIImage imageWithContentsOfFile:path];//UIImageViewUIImageView *imageViewPath = [[UIImageView alloc] initWithFrame:CGRectMake(20, 130, 200, 50)];imageViewPath.image = imagePath;[self.view addSubview:imageViewPath];/**********UIImageView-动画效果*************/UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(130, 240, 60, 60)];imageView.backgroundColor = [UIColor grayColor];imageView.image = [UIImage imageNamed:@"1.png"];/****动画效果相关属性****///创建图片数组//开辟内存空间NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:0];for (int i = 1; i <= 12; i ++) {[array addObject:[UIImage imageNamed:[NSString stringWithFormat:@"player%d.png",i]]];}//设置动画图片,需要接收一个数组,数组里面的类型必须是UIImage类型imageView.animationImages = array;//动画时间:数组里面所有的图片转一圈所用时间imageView.animationDuration = 1;//循环次数:大于0的数:写几就循环几次,结束    0:无限循环imageView.animationRepeatCount = 0;//tagimageView.tag = 1000;[self.view addSubview:imageView];//开始动画
    [imageView startAnimating];//UIButtonUIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];button.frame = CGRectMake(30, 330, 260, 30);button.backgroundColor = [UIColor redColor];[button setTitle:@"button" forState:UIControlStateNormal];[button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];[self.view addSubview:button];
}
#pragma mark - 按钮的点击事件:停止或开始动画
- (void)buttonClick:(UIButton *)button{//找到UIImageViewUIImageView *imageView = (UIImageView *)[self.view viewWithTag:1000];//停止动画
//    [imageView stopAnimating];static BOOL isAnimation = YES;if (isAnimation) {[imageView stopAnimating];isAnimation = NO;}else{[imageView startAnimating];isAnimation = YES;}
}

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

    //时间//第一个参数执行动作相隔的时间//第二个参数通知给谁:self//第三个参数:执行的相关方法//第四个参数:nil//第五个参数:是否重复执行   YES:重复   NO:不重复
//    [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(timer:) userInfo:nil repeats:YES];//self.view.bounds  以(0, 0)点为起点,全屏大小的viewUIImageView *imageView = [[UIImageView alloc] initWithFrame:self.view.bounds];imageView.image = [UIImage imageNamed:@"back2.jpg"];[self.view addSubview:imageView];//动画效果的UIImageViewUIImageView *birdView = [[UIImageView alloc] initWithFrame:CGRectMake(5, 30, 60.5, 48)];//tagbirdView.tag = 1000;//图片数组NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:0];for (int i = 1; i <= 18; i ++) {[array addObject:[UIImage imageNamed:[NSString stringWithFormat:@"DOVE%d.png",i]]];}/**UIImageView的动画属性***/birdView.animationImages = array;birdView.animationDuration = 1;birdView.animationRepeatCount = 0;//开始动画
    [birdView startAnimating];[imageView addSubview:birdView];//控制bird位置[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(changeFrame:) userInfo:nil repeats:YES];
}
#pragma mark - 改变bird的位置
- (void)changeFrame:(NSTimer *)timer{UIImageView *imageView = (UIImageView *)[self.view viewWithTag:1000];static int i = 0;[UIView animateWithDuration:1 animations:^{imageView.frame = CGRectMake(5 + (i++ * 10), 20 +arc4random()%30, 60.5, 48);}];if (5 +(i++ * 10) > 320) {imageView.frame = CGRectMake(5, 20, 60.5, 48);i = 0;}
}
#pragma mark - NSTimer的事件
- (void)timer:(NSTimer *)timer{NSLog(@"timer");
}
#pragma mark - 按钮的点击事件
- (void)buttonClick:(UIButton *)button{//UIView的动画效果//第一个参数:动画执行的时间//第二个参数:执行动作
//    [UIView animateWithDuration:3 animations:^{
//        self.view.backgroundColor = [UIColor colorWithRed:arc4random()%256/255.0 green:arc4random()%256/255.0 blue:arc4random()%256/255.0 alpha:1.0];
//    }];//第一个参数:动画执行的时间//第二个参数:动画延迟执行的时间//第三个参数:动画执行的效果//第四个参数:执行动作//第五个参数:执行完要做的动作之后做的操作[UIView animateWithDuration:3 delay:1 options:UIViewAnimationOptionOverrideInheritedOptions animations:^{self.view.backgroundColor = [UIColor colorWithRed:arc4random()%256/255.0 green:arc4random()%256/255.0 blue:arc4random()%256/255.0 alpha:1.0];} completion:^(BOOL finished) {
//        self.view.backgroundColor = [UIColor orangeColor];
    }];
}

转载于:https://www.cnblogs.com/hyuganatsu/p/UIImageView.html

UIImageView相关推荐

  1. UIImageView 与 UIButton的区别

    2019独角兽企业重金招聘Python工程师标准>>> 相同点: 都能显示图片 不同点: UIButton能处理点击事件,UIImageView不能处理点击时间 UIButton既能 ...

  2. UIImageView图片视图的基本概念和使用方法

    IOS学习笔记(十)之UIImageView图片视图的基本概念和使用方法(博客地址: http://blog.csdn.net/developer_jiangqq ) Author:hmjiangqq ...

  3. UIImageView动画

    设置动画方法一:简易版本的动画(使用block版本) //动画需要持续多久  第一个参数 动画持续的时间 [UIView animateWithDuration:5 animations:^{ //设 ...

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

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

  5. iOS开发——UI基础-UIImage,UIImageView的使用

    1.UIImage 创建UIImage的两种方法 UIImage *image = [UIImage imageNamed:imageNmae];UIImage *image = [UIImage i ...

  6. ios之UIImageView

    UIImageView,顾名思义,是用来放置图片的.使用Interface Builder设计界面时,当然可以直接将控件拖进去并设置相关属性,这就不说了,这里讲的是用代码. 1.创建一个UIImage ...

  7. UI基础视图----UIImageView总结

    UIImageView和UILabel一样,也是UIKit框架中非常常用的视图类.继承关系和UILabel完全一致(都是继承于UIView),功能也相似(用户交互都默认为关,主要用于展示),只不过UI ...

  8. 轻量级UIImageView分类缓存 库 AsyncImageView 使用

    轻量级UIImageView分类缓存 库 AsyncImageView 使用 一: AsyncImageView 主页:https://github.com/nicklockwood/AsyncIma ...

  9. swift学习笔记-UI篇之UIImageView

    1.基本使用 将要使用的图片拖入到项目里,我这里使用的是名为"1.jpg"的图片,然后创建UIImageView,并设置要显示的图片为"1.jpg" //1. ...

最新文章

  1. 点击TableView任一行跳转详情页面会跳转两次的解决办法
  2. redis3.0.2 编译安装 (启动服务方式启动)
  3. bootstraptable获取所有数据_一键获取oracle用户下所有表的表名与其数据量
  4. BZOJ3566 SHOI2014概率充电器(动态规划+概率期望)
  5. autosys file watcher 注意事项
  6. 科学家利用计算机模型,科学家尝试利用计算机模拟整个宇宙的演化
  7. Spring2..5整合Ehacahe
  8. Python __getattribute__ vs __getattr__
  9. PHP魔术方法和魔术变量总结
  10. 如何参加GoToMeeting在线会议
  11. 425 Failed to establish connection.
  12. win10网络诊断为DNS服务器未响应,Win10系统下电脑无法连接网络诊断提示DNS服务器未响应解决方法...
  13. 程序员如何读懂火焰图
  14. 缠中说禅 教你打坐 全集列表
  15. ps批量把文件名添加到图像_自动为带有文件名的投资组合图像添加字幕
  16. RTC实时时钟原理+BKP寄存器
  17. ISTQB中的测试条件是什么?和测试用例的前置条件有什么区别?
  18. matlab用牛顿差值计算三次差值多项式,计算方法用Newton插值多项式求函数的近似值.docx...
  19. AES加密解密SHA1、SHA加密MD5加密
  20. [转]一款可以反编译jar包的java反编译工具-JD-GUI(绿色软件)

热门文章

  1. 家用计算机先驱逝世:Linux之父曾受他启发,马斯克悼念
  2. Nature:大脑佛一点,活得久一点,这是哈佛医学院的最新研究
  3. 华为终于放出方舟编译器源代码!开源平台同步亮相,网友:硬核项目
  4. java版b2b2c社交电商springcloud分布式微服务 (九)服务链路追踪(Spring Cloud Sleuth)...
  5. RocketMQ 4.5.1 双主双从异步复制环境搭建
  6. JavaScript之各种继承方式和优缺点
  7. 360浏览器、chrome开发扩展插件教程(2)为html添加行为
  8. Node.js链式回调
  9. 多线程——实现Callable接口
  10. Exchange-OWA与域控集成-实现单点登录