iOS学习阶段总结-b20120920-多媒体动画
2012-10-02 13:45
465 查看
UIImageView内置的动画功能
UIImageView.animationImages:保存UIImage的一个数组,实用NSArray.arrayWithObjects创建;
UIImageView.animationDuration:所有图片播放一次的总时间;
UIImageView.animationRepeatCount:重复播放次数,值为0时表示持续播放;
UIImageView.startAnimating:开始播放;
随机动画效果(小项目Snow):
随机数:random(),生成[MIN,MAX]之间的一个随机数 (random()%(MAX-MIN)) + MIN
定时函数:NSTimer.scheduledTimerWithTimeInterval;
关键代码
[SnowViewController.m]viewDidLoad
//设置屏幕背景颜色,浅蓝色
self.view.backgroundColor = [UIColor colorWithRed:0.5 green:0.5 blue:1 alpha:1];
//开启定时器,每隔0.05秒执行一次onTimer函数
[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(onTimer) userInfo:nil repeats:YES];
定时函数onTimer
程序运行一段时间后,会出现内存溢出
解决内存溢出:注册动画的结束事件,在动画停止时,回收UIImageView
在上面onTimer函数中commitAnimations之前加入下面代码
[UIView setAnimationDidStopSelector:@selector(onAnimationComplete:finished:context:)];
[UIView setAnimationDelegate:self];
事件处理:
UIImageView.animationImages:保存UIImage的一个数组,实用NSArray.arrayWithObjects创建;
UIImageView.animationDuration:所有图片播放一次的总时间;
UIImageView.animationRepeatCount:重复播放次数,值为0时表示持续播放;
UIImageView.startAnimating:开始播放;
随机动画效果(小项目Snow):
随机数:random(),生成[MIN,MAX]之间的一个随机数 (random()%(MAX-MIN)) + MIN
定时函数:NSTimer.scheduledTimerWithTimeInterval;
关键代码
[SnowViewController.m]viewDidLoad
//设置屏幕背景颜色,浅蓝色
self.view.backgroundColor = [UIColor colorWithRed:0.5 green:0.5 blue:1 alpha:1];
//开启定时器,每隔0.05秒执行一次onTimer函数
[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(onTimer) userInfo:nil repeats:YES];
定时函数onTimer
- (void)onTimer { UIImage *snowImage = [UIImage imageNamed:@"snow.png"]; UIImageView *view = [[UIImageView alloc] initWithImage:snowImage]; [snowImage release]; //随机开始位置,结束位置,大小,速度 int startX = random()%320; int endX = random()%320; int width = random()%MAX_SIZE;//#define定义 int time = (random()%(MAX_TIME - MIN_TIME)) + MIN_TIME;//同上 //开始位置 view.frame = CGRectMake(startX,-1*MAX_SIZE,width,width);//从屏幕上沿出现 view.alpha = 0.25;//半透明 [self.view addSubview:view]; [UIView beginAnimations:nil context:nil]; //速度 [UIView setAnimationDuration:time]; //结束位置 view.frame = CGRectMake(endX,480,width,width); [UIView commitAnimations]; }
程序运行一段时间后,会出现内存溢出
解决内存溢出:注册动画的结束事件,在动画停止时,回收UIImageView
在上面onTimer函数中commitAnimations之前加入下面代码
[UIView setAnimationDidStopSelector:@selector(onAnimationComplete:finished:context:)];
[UIView setAnimationDelegate:self];
事件处理:
- (void)onAnimationComplete:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context { UIImageView *snowView = context; [snowView removeFromSuperview]; [snowView release]; }
相关文章推荐
- iOS学习阶段总结-b20120920-动画转场
- iOS学习阶段总结-b20120920-Quartz 2D绘图
- ios 学习总结之动画
- iOS学习总结----核心动画(2)
- iOS 学习总结之动画
- ios 学习总结之UIView的动画
- ios 学习总结之动画(转)
- iOS学习动画总结
- IOS 学习总结之动画
- ios 学习总结之动画
- iOS☞旋转动画学习总结
- ios FFmpeg第一阶段学习总结
- iOS学习总结----核心动画
- iOS_Core Animation核心动画 基础动画的学习与总结
- ios 学习总结之动画
- ios 学习总结之动画(转)
- ios 学习总结之动画
- web学习阶段总结(2)
- IOS开发学习笔记020-练习总结
- IOS树视图学习总结