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

ios-UI控件精讲之【6】-UIImageView

2016-02-24 21:59 405 查看
原文:http://www.jianshu.com/p/3eaa34649b79


UIImageView属性

创建UIImageView对象
UIImageView *imageView = [[UIImageView alloc] init];


设置frame-->位置和尺寸
imageView.frame = CGRectMake(100, 100, 175, 175);


创建时设置frame
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(100, 100, 267, 400)];

根据图片的大小,设置frame
imageView.frame = CGRectMake(100, 100, image.size.width, image.size.height);

设置背景颜色
imageView.backgroundColor = [UIColor yellowColor];


设置显示的图片
常用创建UIImage的方法:
1.imageName: 后面传入图片的名字
2.imageWithContentOfFile: 图片的全路径
*/
UIImage *image = [UIImage imageNamed:@"1"];

将image对象设置imageView的属性
imageView.image = image;



帧动画

加载所有图片
NSMutableArray *images = [NSMutableArray array];
for (int i = 0; i < 20; i++) {
NSString *imageName = [NSString stringWithFormat:@"%d", i + 1];
UIImage *image = [UIImage imageNamed:imageName];

[images addObject:image];

给imageView设置图片
self.imageView.animationImages = images;

动画执行次数
self.imageView.animationRepeatCount = 2;
默认是0,无限循环

动画执行时间
self.imageView.animationDuration = 1;

开始动画
[self.imageView startAnimating];

停止动画
[self.imageView stopAnimating];
//清空数组里的图片
self.standImages = nil;
self.imageView.animationImages = nil;

过一个时间执行另外一个动作
[self performSelector:@selector(stand) withObject:nil afterDelay:zhaoTime];


播放声音

根据音频文件名加载资源
NSURL *url = [[NSBundle mainBundle] URLForResource:soundName withExtension:@"mp3"];


创建AVPlayerItem的对象
AVPlayerItem *Item = [[AVPlayerItem alloc] initWithURL:url];


创建AVPlayer对象
AVPlayer * player = [[AVPlayer alloc]initWithPlayerItem:Item];

播放声音
[self.player play];


改变声音播放速率
self.player.rate = 1.5;


另一个Item
AVPlayerItem *item2 = [[AVPlayerItem alloc] initWithURL:url];

替换前一个Item
[self.player replaceCurrentItemWithPlayerItem:item2];

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