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

iOS开发UI系列之UIImageView的基本使用

2015-09-26 11:41 603 查看
继承关系
UIImageView --> UIView

一. 什么是UIImageView

lUIKit框架提供了非常多的UI控件,但并不是每一个都很常用,有些控件可能1年内都用不上,有些控件天天用,比如UIButton、UILabel、UIImageView、UITableView等等

lUIImageView极其常用,功能比较专一:显示图片

二. UIImageView的常见属性
1. 创建UIImageView

UIImageView *image = [[UIImageView alloc] init];


2. 设置尺寸

image.frame = CGRectMake(0, 0, goodsW, goodsW);


3. 设置图片

image.image = [UIImage imageNamed:icon];


4. 加载动画图片

@property(nonatomic,copy) NSArray *animationImages; 

5. 动画图片的持续时间

@property(nonatomic) NSTimeInterval animationDuration; 

6. 动画的播放次数(默认是0,代表无限播放)

@property(nonatomic) NSInteger      animationRepeatCount; 

- (void)startAnimating; // 开始动画

- (void)stopAnimating; // 停止动画

- (BOOL)isAnimating; // 是否正在执行动画

三. UIImageView加载动画
1. 首尾方式

// 1.定义一个动画

[UIView beginAnimations:nil context:nil];

// 2.设置动画持续时间

[UIView setAnimationDuration:2.0];


// 3.取出image的frame

CGRect tmepF = self.image.frame;

// 取出image的bounds

CGRect tmepB = self.image.bounds;


// 4.根据按钮的tag判断方向

switch (btn.tag) {

case 10: // 上

   tmepF.origin.y -= f;

   break;

case 20: // 下

   tmepF.origin.y += f;

   break;

}


// 将tmep赋值给按钮

self.image.frame = tmepF;

self.image.bounds = tmepB;


// 提交动画

[UIView commitAnimations];


2. 将图片加载到animationImages

// 6.将图片数组加入到动画中

self.iconImage.animationImages = images;


// 7.设置动画次数

self.iconImage.animationRepeatCount = 1;


// 8.设置动画持续时间

self.iconImage.animationDuration = count * 0.08;


// 9.开始动画

[self.iconImage startAnimating];


3. block 动画

// 慢慢出现(出现动画持续1秒)

[UIView animateWithDuration:1.0 animations:^{

self.hudLabel.alpha = 1.0;

} completion:^(BOOL finished) {


// 1.5秒后,再慢慢消失(消失动画持续1秒)

[UIView animateWithDuration:1.0 delay:1.5 options:kNilOptions animations:^{

self.hudLabel.alpha = 0.0;

} completion:nil];


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