您的位置:首页 > 产品设计 > UI/UE

iOS学习笔记-011.UIImageView的基本介绍和帧动画

2017-01-17 11:06 447 查看
UIImageView的基本介绍和帧动画
一实例化UIImageView
- initWithImage

- initWithImage highlightedImage

二设置图像

三设置显示模式

四序列帧动画基础
属性说明

相关方法

五帧动画的代码

六帧动画的效果

UIImageView的基本介绍和帧动画

一、实例化UIImageView

创建一个UIImageView可以使用以下的方法

1. - initWithImage:

// swift
init(image image:UIImage?)


// objective-c
- (instancetype nonnull)initWithImage:(UIImage * nullable)image


2.- initWithImage: highlightedImage:

// swift
init(image image: UIImage?,highlightedImage highlightedImage: UIImage?)


// objective-c
- (instancetype nonnull)initWithImage:(UIImage * nullable)image
highlightedImage:(UIImage * nullable)highlightedImage


二、设置图像

[imageView setImage:[UIImage imageNamed:@"xm.png"]];


三、设置显示模式

imageView.contentMode = UIViewContentModeScaleAspectFit;


四、序列帧动画基础

UIImageView可以让一系列的图片在特定的时间内按顺序显示

1. 属性说明:

animationImages:要显示的一组图片序列
animationDuration:完整地显示所有图片所需的时间
animationRepeatCount:动画的执行次数(默认为0,代表无限循环)


2. 相关方法:

- (void)startAnimating; 开始动画
- (void)stopAnimating;  停止动画
- (BOOL)isAnimating;  是否正在运行动画


五、帧动画的代码

//
//  ViewController.m
//  03_UIView03_帧动画
//
//  Created by 杞文明 on 15/12/22.
//  Copyright © 2015年 杞文明. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *testIv;

@end

@implementation ViewController

- (void)viewDidLoad {
[super viewDidLoad];

[self setXmAnimotion:11 withImageView:_testIv];
}

//设置动画
-(void)setXmAnimotion:(int) count withImageView:(UIImageView*) imageView{
//步骤
//1.创建一个集合存储图片
NSMutableArray *imageList = [NSMutableArray array];
//2.循环添加图片
for (NSInteger i=1; i<10; i++) {
[imageList addObject:[UIImage imageNamed:[NSString stringWithFormat:@"%ld.png",i]]];
}

//3.把图片集合添加到imageview中
[imageView setAnimationImages:imageList];
//4.动画时长
[imageView setAnimationDuration:2];
//5.循环次数
[imageView setAnimationRepeatCount:2];
//6.开始动画
[imageView startAnimating];

}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

@end


六、帧动画的效果

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐