- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view. /*********UIImage***********/
//由名字直接读取图片
//优点:用时相对较短
//缺点:读取之后会占用内存
//如果图片较小,用名字直接读取 UIImage *imageName = [UIImage imageNamed:@"1.png"]; //UIImageView
UIImageView *imageViewName = [[UIImageView alloc] initWithFrame:CGRectMake(, , , )];
imageViewName.image = imageName;
[self.view addSubview:imageViewName]; //由图片的路径读取图片
//优点:读取之后不会占用内存
//缺点:用时相对较长
//如果图片较大,用路径直接读取 //获取图片路径:相对路径
//第一个参数:文件的名字
//第二个参数:文件的类型
NSString *path = [[NSBundle mainBundle] pathForResource:@"map" ofType:@"png"];
UIImage *imagePath = [UIImage imageWithContentsOfFile:path];
//UIImageView
UIImageView *imageViewPath = [[UIImageView alloc] initWithFrame:CGRectMake(, , , )];
imageViewPath.image = imagePath;
[self.view addSubview:imageViewPath]; /**********UIImageView-动画效果*************/
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(, , , )];
imageView.backgroundColor = [UIColor grayColor];
imageView.image = [UIImage imageNamed:@"1.png"]; /****动画效果相关属性****/
//创建图片数组
//开辟内存空间
NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:];
for (int i = ; i <= ; i ++) {
[array addObject:[UIImage imageNamed:[NSString stringWithFormat:@"player%d.png",i]]];
} //设置动画图片,需要接收一个数组,数组里面的类型必须是UIImage类型
imageView.animationImages = array;
//动画时间:数组里面所有的图片转一圈所用时间
imageView.animationDuration = ;
//循环次数:大于0的数:写几就循环几次,结束 0:无限循环
imageView.animationRepeatCount = ; //tag
imageView.tag = ; [self.view addSubview:imageView]; //开始动画
[imageView startAnimating]; //UIButton
UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
button.frame = CGRectMake(, , , );
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{
//找到UIImageView
UIImageView *imageView = (UIImageView *)[self.view viewWithTag:];
//停止动画
// [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)点为起点,全屏大小的view
UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.view.bounds];
imageView.image = [UIImage imageNamed:@"back2.jpg"];
[self.view addSubview:imageView]; //动画效果的UIImageView
UIImageView *birdView = [[UIImageView alloc] initWithFrame:CGRectMake(, , 60.5, )];
//tag
birdView.tag = ; //图片数组
NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:];
for (int i = ; i <= ; i ++) {
[array addObject:[UIImage imageNamed:[NSString stringWithFormat:@"DOVE%d.png",i]]];
} /**UIImageView的动画属性***/
birdView.animationImages = array;
birdView.animationDuration = ;
birdView.animationRepeatCount = ;
//开始动画
[birdView startAnimating]; [imageView addSubview:birdView]; //控制bird位置
[NSTimer scheduledTimerWithTimeInterval: target:self selector:@selector(changeFrame:) userInfo:nil repeats:YES];
}
#pragma mark - 改变bird的位置
- (void)changeFrame:(NSTimer *)timer{
UIImageView *imageView = (UIImageView *)[self.view viewWithTag:];
static int i = ;
[UIView animateWithDuration: animations:^{
imageView.frame = CGRectMake( + (i++ * ), +arc4random()%, 60.5, );
}];
if ( +(i++ * ) > ) {
imageView.frame = CGRectMake(, , 60.5, );
i = ;
}
}
#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: delay: options:UIViewAnimationOptionOverrideInheritedOptions animations:^{
self.view.backgroundColor = [UIColor colorWithRed:arc4random()%/255.0 green:arc4random()%/255.0 blue:arc4random()%/255.0 alpha:1.0];
} completion:^(BOOL finished) {
// self.view.backgroundColor = [UIColor orangeColor];
}];
}

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. .NET平台开源项目速览(3)小巧轻量级NoSQL文件数据库LiteDB

    今天给大家介绍一个不错的小巧轻量级的NoSQL文件数据库LiteDB.本博客在2013年也介绍过2款.NET平台的开源数据库: 1.[原创]开源.NET下的XML数据库介绍及入门 2.[原创]C#开源 ...

  2. linux下的常用命令

    1 fg切换前后台作业 将后台作业转换为前台作业,”fg %作业号“ 2 stty改变和打印终端行设置 tostop 阻止后台作业写终端,stty -a显示终端的所有选项 3 uname查看机子信息 ...

  3. make things simple

    以前看过一篇文章,具体内容不记得了,只记得它的结论了:懒是人类进步的源动力.当时觉得结论有点新颖,文中列举了大量的实例证明这个结论,其中重点强调了计算机学科.我本身从事算是计算机相关的工作,对文中的部 ...

  4. EXP/IMP迁移案例,IMP遭遇导入表的表空间归属问题

    生产环境: 源数据库:Windows Server + Oracle 11.2.0.1 目标数据库:SunOS + Oracle 11.2.0.3 1.确认迁移需求:源数据库cssf 用户所有表和数据 ...

  5. (十九)WebGIS中I查询的原理及设计(包含AGS、GeoServer、Supermap)

    文章版权由作者李晓晖和博客园共有,若转载请于明显处标明出处:http://www.cnblogs.com/naaoveGIS/. 1.背景 我们在使用arcmap时,经常会用到被称为I查询的工具.具体 ...

  6. 解析C#类中的构造函数

    <解析C#类中的构造函数> 一.  C#中的构造函数概述: C#中类包含数据成员和函数成员.函数成员提供了操作类中数据的某些功能,包括方法.属性.构造器和终结器.运算符和索引器. 构造函数 ...

  7. Ftp上传下载 C#

    public class MyFtpClass { private readonly string _destIp; private readonly string _userName; privat ...

  8. SQL Server基础之索引

     索引用于快速找出在某个列中有某一特定值的行,不使用索引,数据库必须从第一条记录开始读完整个表,直到找出相关的行.表越大,查询数据所花费的时间越多,如果表中查询的列有一个索引,数据库能快速到达一个位置 ...

  9. QTableWidget行选中/删除/添加行

    1  均分各列 tableWidget->horizontalHeader()->setStretchLastSection(true); //就是这个地方 tableWidget-> ...

  10. Visual Studio 2015 正式版 官方下载地址

    Visual Studio 2015昨日正式版发布,期待7.29正式版Win10的发布. Visual Studio 2015 各版本简体中文与English的下载地址详见下文. 另: Visual ...