iOS-UIImageView的总结
1.UIImageView的使用模式contentMode
-
contentMode有以下几种:
-
带有scale的:图片有可能会拉伸
- UIViewContentModeScaleToFill
- 将图片拉伸至填充整个imageView
```
- 带有aspect单词的:保持图片原来的宽高比
- UIViewContentModeScaleAspectFit
- 保证刚好能看到图片的全部
- UIViewContentModeScaleAspectFill
- 拉伸至图片的宽度或者高度跟imageView一样
```
- 没有scale单词的:图片不会被拉伸,保持图片的原尺寸, 只是位置变化
- UIViewContentModeCenter
- UIViewContentModeTop
- UIViewContentModeBottom
- UIViewContentModeLeft
- UIViewContentModeRight
- UIViewContentModeTopLeft
- UIViewContentModeTopRight
- UIViewContentModeBottomLeft
- UIViewContentModeBottomRight
```
###2.其他属性
- 裁剪超出imageView边框的部分
```objc
imageView.clipsToBounds = YES;
连续播放动画
可以使用UIImageVIew连续播放动画,要用到这几个属性和方法:
@property(nonatomic,copy) NSArray *animationImages;
@property(nonatomic) NSTimeInterval animationDuration; // for one cycle of images. default is number of images * 1/30th of a second (i.e. 30 fps)
@property(nonatomic) NSInteger animationRepeatCount; // 0 means infinite (default is 0)
- (void)startAnimating;
举例:
_imageView.animationImages = imagesArray;
_imageView.animationDuration = number * 0.08;
_imageView.animationRepeatCount = [prefix isEqualToString:@"stand"]?0:1;
// 设置图片
[_imageView startAnimating];
[_imageView performSelector:@selector(StandFunc:) withObject:nil afterDelay:_imageView.animationDuration inModes:nil];
把需要播放的图片的数组传递给animationImages,然后设置动画时间animationDuration和重复次数animationRepeatCount,就可以开始动画了。最后还可以设置动画结束后的行为 performSelector:afterDelay: inModes方法
3.加入音频的方法
1.导入头文件
#import <AVFoundation/AVFoundation.h>
2.设置播放对象
@property (strong, nonatomic)AVPlayer *player;
3.给出音频路径,并播放
NSURL *url = [[NSBundle mainBundle] URLForResource:@"dazhao" withExtension:@"mp3"];
_player = [AVPlayer playerWithURL:url];
[_player play];