学习第一天,虽然从今天到未来的两周都是学前训练阶段(适应环境),但是我还是很认真的听老师讲的每一句话,努力的做笔记,每天坚持写博客,把我从新手开始的一点一滴分享给别人。
今天直接学习的用object-c学一些简单的程序,老师用了一些有趣的例子讲课,不是很乏味。
- //
- // ViewController.m
- // MySecondDemo Snow
- //
- // Created by qingyun on 16/5/17.
- // Copyright © 2016年 qingyun. All rights reserved.
- //
- #import "ViewController.h"
- @interface ViewController ()
- @end
- @implementation ViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view, typically from a nib.
- //创建背景视图
- UIImageView *BackImage=[[UIImageView alloc]init];
- BackImage.frame=self.view.frame;
- BackImage.backgroundColor=[UIColor redColor];
- BackImage.image=[UIImage imageNamed:@"3.jpg"];
- [self.view addSubview:BackImage];
- //创建定时器
- [NSTimer scheduledTimerWithTimeInterval:0.00000001 target:self
- selector:@selector(click) userInfo:nil repeats:YES];
- }
- -(void)click//定时器
- {
- //创建雪花视图
- UIImageView *SnowImage=[[UIImageView alloc]init];
- SnowImage.frame=CGRectMake(arc4random()%321, 10, 50, 50);
- //SnowImage.backgroundColor=[UIColor whiteColor];
- SnowImage.image=[UIImage imageNamed:@"snow1.png"];
- [self.view addSubview:SnowImage];
- //开始动画
- [UIView beginAnimations:nil context:(__bridge void * _Nullable)(SnowImage)];
- //设置动画时长
- [UIView setAnimationDuration:3];
- //设置动画代理
- [UIView setAnimationDelegate:self];
- //设置动画位置
- SnowImage.frame=CGRectMake(arc4random()%321,
- arc4random()%668, 50, 50);
- //结束、提交程序
- [UIView commitAnimations];
- }
- - (void)animationDidStop:(NSString *)
- animationID finished:(NSNumber *)
- finished context:(void *)context//动画从上到下执行完后需要移除雪花时就要执行这个事件,
- {
- UIImageView*imageView=(__bridge UIImageView*)context;//context是一个中间者,在这里代表SnowImage,一张图片;
- //移除出现过的视图
- [imageView removeFromSuperview];
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- @end