//1.加毛玻璃
UIToolbar *toolbar = [[UIToolbar alloc] init];
//2.设置frame
toolbar.frame = self.bgImageView.bounds;
//3.设置样式和透明度
toolbar.barStyle = UIBarStyleBlack;
toolbar.alpha = 0.98;
//4.加到背景图片上
[self.bgImageView addSubview:toolbar];
UIImageView *imageView = [[UIImageView alloc] init];
imageView.image = [UIImage imageNamed:@"1"];
imageView.frame = CGRectMake(100, 100, 267, 400);
imageView.frame = (CGRect){{100,100},{100,150}};
[self.view addSubview:imageView];
UIImageView *imageView = [[UIImageView alloc] init];
UIImage *image = [UIImage imageNamed:@"1"];
imageView.frame = CGRectMake(100, 100, image.size.width, image.size.height);
imageView.image = image;
[self.view addSubview:imageView];
UIImage *image = [UIImage imageNamed:@"1"];
UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(100, 100, 167, 300)];
imageView.image = image;
[self.view addSubview:imageView];
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"1"]];
imageView.center = CGPointMake(self.view.frame.size.width * 0.5, self.view.frame.size.height * 0.5);
[self.view addSubview:imageView];
NSMutableArray<UIImage *> *imageArr = [NSMutableArray array];
for (int i = 0; i < 20; ++i) {
//获得图片名称
NSString *imageName = [NSString stringWithFormat:@"%d",i+1];
//创建UImage对象
UIImage *image = [UIImage imageNamed:imageName];
//加入数组
[imageArr addObject:image];
}
self.imageView.animationImages = imageArr;
self.imageView.animationRepeatCount = 0;
self.imageView.animationDuration = 1.0;
[self.imageView startAnimating];
[self.imageView stopAnimating];
Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘* -[__NSArrayM insertObject:atIndex:]: object cannot be nil’
-(NSArray*)loadAllImagesWithimagePrefix:(NSString*)
imagePrefix count:(int)count
{
NSMutableArray<UIImage *> *imageArr = [
NSMutableArray array];
for (int i = 0; i < count; ++i) {
//获得图片名称
NSString *imageName = [NSString
stringWithFormat:@"%@_%d",imagePrefix,i+1];
//创建UIImage对象
UIImage *image = [UIImage imageNamed:imageName];
//加入数组
[imageArr addObject:image];
}
return imageArr;
}
self.standImageArr = [self
loadAllImagesWithimagePrefix:@"stand" count:10];
self.smillSkillImageArr = [self
loadAllImagesWithimagePrefix:@"xiaozhao3" count:39];
self.bigSkillImageArr = [self
loadAllImagesWithimagePrefix:@"dazhao" count:87];
-(IBAction)stand{
//设置图片动画
self.imageView.animationImages = self.standImageArr;
//设置动画的播放次数
self.imageView.animationRepeatCount = 0;
//设置动画播放时长
self.imageView.animationDuration = 1;
//开始动画
[self.imageView startAnimating];
}
-(IBAction)smallSkill{
//设置图片动画
self.imageView.animationImages = self.smillSkillImageArr;
//设置动画的播放次数self.imageView.animationRepeatCount = 1;
//设置动画播放时长
self.imageView.animationDuration = 2.5;
//开始动画[self.imageView startAnimating];
//站立(延迟执行)
// Selector 方法
// Object 参数
// afterDelay 时间
[self performSelector:@selector(stand) withObject:nil afterDelay:self.imageView.animationDuration];
}
- (IBAction)bigSkill{
//设置图片动画
self.imageView.animationImages = self.bigSkillImageArr;
//设置动画的播放次数
self.imageView.animationRepeatCount = 1;
//设置动画播放时长
self.imageView.animationDuration = 4;
//开始动画
[self.imageView startAnimating];
//站立(延迟执行)
// Selector 方法
// Object 参数
// afterDelay 时间
[self performSelector:@selector(stand) withObject:nil afterDelay:self.imageView.animationDuration];
}
/*图片的两种加载方式:
1> imageNamed:
a. 就算指向它的指针被销毁,该资源也不会被从内存中干掉
b. 放到Assets.xcassets的图片,默认就有缓存
c. 图片经常被使用
2> imageWithContentsOfFile:
a. 指向它的指针被销毁,该资源会被从内存中干掉
b. 放到项目中的图片就不由缓存
c. 不经常用,大批量的图片*/
NSString *imagePath = [[NSBundle mainBundle]
pathForResource:imageName ofType:@"png"];
UIImage *image = [UIImage
imageWithContentsOfFile:imagePath];
- (IBAction)gameOver {
//将强指针指向的内存置为空
self.standImageArr = nil;
self.smillSkillImageArr = nil;
self.bigSkillImageArr = nil;
self.imageView.animationImages = nil;
}
需要导入框架#import
@property (nonatomic, strong) AVPlayer *player;
//1 资源的URL地址
NSURL *url = [[NSBundle mainBundle]
URLForResource:@"mySong1.mp3" withExtension:nil];
//2 创建播放器曲目
AVPlayerItem *playItem = [[AVPlayerItem
alloc] initWithURL:url];
//3 创建播放器
self.player = [[AVPlayer alloc]
initWithPlayerItem:playItem];
[self.player play];
//创建播放器
self.player = [[AVPlayer alloc] init];
//播放
NSURL *url = [[NSBundle mainBundle] URLForResource:musicName withExtension:nil];
AVPlayerItem *playItem = [[AVPlayerItem alloc] initWithURL:url];
[self.player replaceCurrentItemWithPlayerItem:playItem];
[self.player play];
self.player.rate = 1.5;
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有