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

[iOS]UIImageView动画相关

2014-02-23 12:51 309 查看
[iOS]UIImageView动画相关

用UIImageView自带方法实现简单动画

Demo:http://download.csdn.net/detail/u012881779/9734998

#import "FirstViewController.h"

@interface FirstViewController ()
@property (strong, nonatomic) UIImageView *loadingImageView;

@end

@implementation FirstViewController
@synthesize loadingImageView = _loadingImageView;

- (void)viewDidLoad {
[super viewDidLoad];
// 加载本地动画
NSMutableArray *array = [[NSMutableArray alloc] initWithObjects:
[UIImage imageNamed:@"loading_image0.png"],
[UIImage imageNamed:@"loading_image1.png"],
[UIImage imageNamed:@"loading_image2.png"],
[UIImage imageNamed:@"loading_image3.png"],
[UIImage imageNamed:@"loading_image4.png"],
[UIImage imageNamed:@"loading_image5.png"],
[UIImage imageNamed:@"loading_image6.png"],
[UIImage imageNamed:@"loading_image7.png"],
nil];
_loadingImageView = [[UIImageView alloc] init];
_loadingImageView.animationImages = array;
// 用于图像的一个循环, 默认为 图像数量*1/30秒(即30fps-每秒传输帧数)
_loadingImageView.animationDuration = 1;
_loadingImageView.hidden = YES;
[_loadingImageView setFrame:CGRectMake(10, 74, 34, 34)];
[self.view addSubview:_loadingImageView];
}

// 开始加载动画
- (void)startLoadingAnimation {
if (_loadingImageView != nil) {
_loadingImageView.hidden = NO;
[_loadingImageView startAnimating];
}
}

// 停止加载动画
- (void)stopLoadingAnimation {
if (_loadingImageView != nil) {
_loadingImageView.hidden = YES;
[_loadingImageView stopAnimating];
}
}

- (IBAction)animationAction:(id)sender {
UIButton *tempBut = (UIButton *)sender;
if(tempBut.tag == 200){
// 开始动画
[self startLoadingAnimation];
}else if (tempBut.tag == 201){
// 停止动画
[self stopLoadingAnimation];
}
}

@end
 示意图:

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