UIImageView与基本动画gif
UIImageView 作用:[用来进行图片展示]
UIImageView
UIImageView初始化
initWithImage:如果设置frame,图片的size就是 imageView的size
UIImage的初始化方法
1、imageNamed:方法
imageNamed:是UIImage的一个类方法,它做的事情比我们看到的要稍微多一些。它的加载流程如下:
a. 系统会去检查系统缓存中是否存在该名字的图像,如果存在则直接返回。
b. 如果系统缓存中不存在该名字的图像,则会先加载到缓存中,在返回该对象。
观察上面的操作我们发现系统会缓存我们使用imageNamed:方法加载的图像时候,系统会自动帮我们缓存。这种机制适合于那 种频繁用到界面贴图类的加载,但如果我们需要短时间内频繁的加载一些一次性的图像的话,最好不要使用这种方法。
imageView支持的图片: 首选png,jpg
2、imageWithContentsOfFile:和imageWithData:方法
图像会被系统以数据方式加载到程序。当你不需要重用该图像,或者你需要将图像以数据方式存储到数据库,又或者你要通 过网络下载一个很大的图像时,请尽量使用imageWithData的方式加载图像。
//两个将图片转换成data的方法(比如:服务器端上传头像,图片缓存数据库)
NSData * __nullable UIImagePNGRepresentation(UIImage * __nonnull image)
//可以进行压缩来操作
NSData * __nullable UIImageJPEGRepresentation(UIImage * __nonnull image, CGFloat compressionQuality);
设置圆角和边框颜色
(1)设置圆角
imageView.layer.masksToBounds = YES;
imageView.layer.cornerRadius = 10;
(2)设置边框颜色和大小
imageView.layer.borderColor = [UIColor orangeColor].CGColor;
imageView.layer.borderWidth = 2;
contentMode属性(Demo)
这个属性是用来设置图片的显示方式,如居中、居右,是否缩放等,有以下几个常量可供设定:

UIViewContentModeScaleToFill
UIViewContentModeScaleAspectFit
UIViewContentModeScaleAspectFill
UIViewContentModeRedraw
UIViewContentModeCenter
UIViewContentModeTop
UIViewContentModeBottom
UIViewContentModeLeft
UIViewContentModeRight
UIViewContentModeTopLeft
UIViewContentModeTopRight
UIViewContentModeBottomLeft
UIViewContentModeBottomRight
注意以上几个常量,凡是没有带Scale的,当图片尺寸超过 ImageView尺寸时,只有部分显示在ImageView中。 UIViewContentModeScaleToFill属性会导致图片变形,图片填充满frame(默认)。
UIViewContentModeScaleAspectFit会保证图片比例不变,而且全部显示在ImageView中,这意味着ImageView会有部分空白。 UIViewContentModeScaleAspectFill也会证图片比例不变,但是是填充整个ImageView的,可能只有部分图片显示出来。(有一部分会被裁切掉)
图片拉伸(resizedImage:)(Demo:)
UIImage的图片拉伸方法
stretchableImageWithLeftCapWidth:topCapHeight:
leftCapWidth ,是左侧需要保留的像素数,topCapHeight是顶部需要保留的像素数,然后中间的1像素用于中间的平铺,达到最后所需 要的尺寸。效果相当于只能保持一边固定,拉伸另一边。
注意:只是对一个像素进行复制到一定宽度。而图像后面的剩余像素也不会被拉伸。
图片动画处理
1.基本动画常用API:
-isAnimation:
-startAnimation:
-stopAnimation:
-setAnimationImages:
-setAnimationDuration:
-setAnimationRepeatCount:
2.使用一张GIF图,完成动画(需要使用CoreText框架,需要导入ImageIO框架)
GIF ==> Data ==> 获取gif帧数(总数量) ==> 获取指定帧的图像 ==> 获取指定图像的属性 ==> 获取属性中的GIF属性 ==> 找出持续时间 ==> 拿到总时间 ==> 设置iamgeView的基本属性完成动画
//Create an image source reading from `data'
CGImageSourceRef __nullable CGImageSourceCreateWithData(CFDataRef __nonnull data, CFDictionaryRef __nullable options)
/* Return the number of images (not including thumbnails) in the image
* source `isrc'. */
size_t CGImageSourceGetCount(CGImageSourceRef __nonnull isrc)
/* Return the image at `index' in the image source `isrc'. The index is
zero-based. */
CGImageRef __nullable CGImageSourceCreateImageAtIndex(CGImageSourceRef __nonnull isrc, size_t index, CFDictionaryRef __nullable options)
/* Return the properties of the image source `isrc’.*/
CFDictionaryRef __nullable CGImageSourceCopyProperties(CGImageSourceRef __nonnull isrc, CFDictionaryRef __nullable options)
//获取指定的关于GIF属性:(const CFStringRef kCGImagePropertyGIFDictionary)
*frameProperties = [properties:( *)kCGImagePropertyGIFDictionary];
//获取图片的持续时间(const CFStringRef kCGImagePropertyGIFDelayTime)
NSNumber *lastTime = [frameProperties objectForKey:(NSString *) kCGImagePropertyGIFDelayTime];
注意内存管理:Core核心框架的对象需要使用对应的release方式,ARC无法对Core核心框架的对象做管理
CFRelease(),CGImageRelease(),等
UIImageView与基本动画gif的更多相关文章
- UIImageView的animationImages动画
UIImageView的animationImages动画 UIImageView的animationImages,只有在做非常规动画的时候才有优势,比方说下图中左侧动画.如果用来做下图中的右侧动画, ...
- UIImageView 自带动画+N张图片实现很炫的动画
gitHub上又看到个很炫的动画:https://github.com/MartinRGB/GiftCard-iOS 看了看他的代码,发现核心动画(就是把按钮包装成一个礼物盒)其实很简单,就是把一 ...
- uiimageView连续帧动画
// // MJViewController.m // 05-汤姆猫 // // Created by apple on 14-3-24. // Copyright (c) 2014年 itc ...
- iOS开发之--UIImageView的animationImages动画
图片动画实现,代码如下: -(UIImageView *)animationImageView { if (!_animationImageView) { _animationImageView= [ ...
- IOS UIImageView的帧动画
● UIImageView可以让一系列的图片在特定的时间内按顺序显示 ● 相关属性解析: ● animationImages:要显示的图片(一个装着UIImage的NSArray) ● animati ...
- [Xcode 实际操作]六、媒体与动画-(13)使用UIImageView制作帧动画
目录:[Swift]Xcode实际操作 本文将演示如何将导入的序列图片,转换为帧动画. 在项目导航区打开资源文件夹[Assets.xcassets] [+]->[Import]->选择图片 ...
- UIImageView的序列帧动画
#pragma mark - 开始动画 - (IBAction)startAnimation { // 1.1 加载所有的图片 NSMutableArray<UIImage *> *ima ...
- uiimageview 的 animation 动画
NSMutableArray *meiArr = [NSMutableArray arrayWithCapacity:4]; for (int i = 0; i < 4; i++) { NSSt ...
- UIImageView 动画 / UIImage 方向
UIImage 方向 UIImage imageOrientation是相对当前屏幕的横竖屏来判断方向 如果本身是横屏, 照片也是横屏的话, 方向是正方向 BOOL b1 = (originalIma ...
随机推荐
- 『题解』洛谷P4016 负载平衡问题
title: categories: tags: - mathjax: true --- Problem Portal Portal1:Luogu Portal2: LibreOJ Descripti ...
- Consul安装集群搭建
1 consul的安装和配置 1.1 consul agent 命令介绍 下载consul_1.0.0_linux_amd64.zip解压,里面只有一个consul可执行文件,其中,consul最常用 ...
- js解析json报错Unexpected token i in JSON at position 1
因为后台json是手动拼接的,在拼接时偷了懒,不想转义,所以就用了单引号,结果js解析时悲催了 这里记录一下,被解析的json字符串必须键值对都用双引号包起来,必须是双引号 默默罚抄一百遍
- ubuntu中nfs安装
Ubuntu Nfs服务器安装 nfs服务器在嵌入式开发中非常常用,可以实现主机和开发板共享文件. 1.安装软件包 sudo apt-get install nfs-common nfs- ...
- Oracle基础:数据库操作_数据库事务_表的锁定
数据库操作语句: INSERT INTO 表名[(字段列表)] VALUES ( 表达式列表); 例子:INSERT INTO emp(empno,ename,job,hiredate) VALUES ...
- [RAM] FPGA的学习笔记——RAM
1.RAM——随机存取存储器, 分为SRAM和DRAM. SRAM:存和取得速度快,操作简单.然而,成本高,很难做到很大.FPGA的片内存储器,就是一种SRAM,用来存放程序,以及程序执行过程中,产生 ...
- Python 常用模块系列(2)--time module and datatime module
import time print (help(time)) #time帮助文档 1. time模块--三种时间表现形式: 1° 时间戳--如:time.time() #从python创立以来,到当 ...
- 安装Fedora后
更新操作系统版本: https://fedoraproject.org/wiki/DNF_system_upgrade 靠谱: 设置ssh:ssh生成公钥私钥.默认root(.ssh/confi ...
- Ubuntu 16.04 更改apt源
1 修改apt源配置文件,把/etc/apt/sources.list替换为以下内容: sudo gedit /etc/apt/sources.list deb http://mirrors.aliy ...
- Linux下为知笔记和蚂蚁笔记测评,推荐蚂蚁笔记!(非广告)
本人由于学习Linux,需要一款可以在Linux平台下可以运行的一款软件,了解到为知笔记之笔记(下文以W代替)和蚂蚁笔记(下文以M代替)比较出名,由于某云和某象笔记在linux平台下没有对应的软件,所 ...