IOS--UIImageView--帧动画
来源:互联网 发布:弹幕播放器源码 编辑:程序博客网 时间:2024/05/23 15:37
帧动画
- 由于没有学习gif的制作,所以只能截几张图来看一看咯<求mac上怎么制作gif>
play方法
- 加载所有动画图片
- 设置动画图片
- 设置播放次数
- 设置图片
- 设置动画时间
- 开始动画
- 播放完毕后执行的方法
- (void)play:(NSString *)filenamePrefix count:(int)count{ // 加载所有的动画图片 NSMutableArray *images = [NSMutableArray array]; for (int i = 1; i<=count; i++) { NSString *filename = [NSString stringWithFormat:@"%@_%d", filenamePrefix, i]; NSString *file = [[NSBundle mainBundle] pathForResource:filename ofType:@"png"]; UIImage *image = [UIImage imageWithContentsOfFile:file]; [images addObject:image]; } // 设置动画图片 self.imageView.animationImages = images; // 设置播放次数 self.imageView.animationRepeatCount = [filenamePrefix isEqualToString:@"stand"] ? 0 :1; // 设置图片 self.imageView.image = [UIImage imageNamed:@"stand_1"]; // 设置动画的时间 self.imageView.animationDuration = count * 0.04; // 开始动画 [self.imageView startAnimating]; if ([filenamePrefix isEqualToString:@"stand"]) return; // 播放完动画以后站着(延迟self.imageView.animationDuration时间后调用self的stand方法) [self performSelector:@selector(stand) withObject:nil afterDelay:self.imageView.animationDuration];}
简单加载音频
- 步骤
- 导入音频头文件
- 创建音频属性
- 创建一个音频文件的URL
- 创建播放器
- 开始播放
#import <AVFoundation/AVFoundation.h>@property (strong, nonatomic) AVPlayer *player;// 创建一个音频文件的URL(URL就是文件路径对象)NSURL *url = [[NSBundle mainBundle] URLForResource:@"dazhao" withExtension:@"mp3"];// 创建播放器self.player = [AVPlayer playerWithURL:url];// 播放[self.player play];
源码
//// ViewController.m// 拳皇帧动画//// Created by MacBookPro on 15/8/9.// Copyright © 2015年 sky5156. All rights reserved.//#import "ViewController.h"#import <AVFoundation/AVFoundation.h>@interface ViewController ()//拿到storyboard中的imageView@property (weak, nonatomic) IBOutlet UIImageView *imageView;//放点音乐@property (nonatomic, strong) AVPlayer *player;@end@implementation ViewController- (void)viewDidLoad { [super viewDidLoad]; //加个边框 CALayer *layer = [self.imageView layer]; layer.borderColor = [UIColor redColor].CGColor; layer.borderWidth = 5.0f; [self stand];}- (IBAction)stand { [self play:@"stand" count:10];}- (IBAction)dead { [self play:@"dead" count:23];}- (IBAction)run { [self play:@"run" count:6];}- (IBAction)xiaozhao { [self play:@"xiaozhao1" count:20]; [self playMusic:@"xiaozhao1"]; [self performSelector:@selector(xiaozhao2) withObject:nil afterDelay:20 * 0.06]; // [self play:@"xiaozhao3" count:39];}- (IBAction)dazhao { [self play:@"dazhao" count:87]; [self playMusic:@"dazhao"];}- (IBAction)install_b { [self play:@"install_b" count:29];}- (void)xiaozhao2{ [self play:@"xiaozhao2" count:35]; [self playMusic:@"xiaozhao2"]; [self performSelector:@selector(xiaozhao3) withObject:nil afterDelay:35 * 0.06];}-(void)xiaozhao3{ [self play:@"xiaozhao3" count:39]; [self playMusic:@"xiaozhao3"];}- (void)playMusic:(NSString *)music{ NSString *urlString = [NSString stringWithFormat:@"%@",music]; // NSString *urlName = [[NSBundle mainBundle] pathForResource:urlString ofType:@"mp3"]; NSURL *url = [[NSBundle mainBundle] URLForResource:urlString withExtension:@"mp3"]; self.player= [AVPlayer playerWithURL:url]; [self.player play];}- (void)play:(NSString *)preFixName count:(int)count{ //加载动画 NSMutableArray *images = [NSMutableArray array]; for (int i = 1; i<=count; i++) { NSString *fileName = [NSString stringWithFormat:@"%@_%d",preFixName,i]; NSString *name = [[NSBundle mainBundle] pathForResource:fileName ofType:@"png"]; UIImage *image = [UIImage imageWithContentsOfFile:name]; [images addObject:image]; } //设置动画的 self.imageView.animationImages = images; self.imageView.image = [UIImage imageNamed:@"stand_1"]; self.imageView.animationRepeatCount = [preFixName isEqualToString:@"stand"]?0 : 1; self.imageView.animationDuration = count*0.06; [self.imageView startAnimating]; //播放完以后站着 if ([preFixName isEqualToString:@"stand"]) return; [self performSelector:@selector(stand) withObject:nil afterDelay:count *0.06];}@end
- github源代码地址:
https://github.com/LGLee/FrameAnimation
0 0
- IOS--UIImageView--帧动画
- iOS之UIImageView帧动画
- [iOS]UIImageView动画相关
- [IOS]UIImageView动画
- iOS中的动画:核心动画Core Animation, UIView动画, Block动画, UIImageView的帧动画.
- iOS UIImageview实现简单动画
- iOS -UI-06 UIImageView 动画
- iOS开发UIImageView动画效果
- UIImageView帧动画
- UIImageView帧动画
- UIImageView播放帧动画
- UIImageView 的帧动画
- UIIMageView实现帧动画
- IOS 开发之UIImageView帧动画的内存管理
- ios开发-支持gif动画的UIImageView
- ios UIimageView 手势移动动画效果
- iOS:UIimageView切换图片渐入渐出的动画
- iOS:UIimageView切换图片渐入渐出的动画
- 计蒜客 难题题库 012 最后一个单词的长度
- 信息发布
- OpenGL ES 模板
- android Installation failed due to invalid URI! 错误处理
- Codeforces 5C
- IOS--UIImageView--帧动画
- 计蒜客 难题题库 013 整数转换成罗马数字
- Singleton---单例模式(创建型)
- C#写的FlappyBird
- uva 11361 Investigating Div-Sum Property 数位dp
- 编程之美----2.21 只考加法的面试题
- 项目实战JS之滚动条
- Codeforces 567F
- 黑马程序员-----java基础之运算符----与(&)、或(|)、非(!)、异或(^)、短路与(&&)等