《30天精通iPhone手机编程》-Day25-雪花

        CGPointMake 、CGRectMake 、CGSizeMake是iphone os中几何图形动画构建类型的一种,常用在二维控件显示:

CGPoint     CGPointMake(CGFloat x,CGFloat y);

CGRect      CGRectMake(CGFloat x,CGFloat y,CGFloat width,CGFloat height);

CGSize      CGSizeMake(CGFloat width,CGFloat height);

- (void)viewDidLoad {
	[super viewDidLoad];
	//定义视图的背景颜色为冷色
	self.view.backgroundColor = [UIColor colorWithRed:0.5 green:0.5 blue:1.0 alpha:1.0];
	flakeImage = [UIImage imageNamed:@"flake.png"];
	//定义定时器
	[NSTimer scheduledTimerWithTimeInterval:(0.05) target:self selector:@selector(onTimer) userInfo:nil repeats:YES];
}
//定时期对象选择器方法
- (void)onTimer
{
	UIImageView* flakeView = [[UIImageView alloc] initWithImage:flakeImage];
	//图像的开始坐标x
	int startX = round(random() % 320);
    //图像的结束坐标x
	int endX = round(random() % 320);
    //定义图像的大小范围随机数值
	double scale = 1 / round(random() % 100) + 1.0;
    //定义图像的速度随机值
	double speed = 1 / round(random() % 100) + 1.0;
	//定义图像视图开始坐标和尺寸
	flakeView.frame = CGRectMake(startX, -100.0, 25.0 * scale, 25.0 * scale);
	flakeView.alpha = 0.25;
	[self.view addSubview:flakeView];
	//视图动画开始
	[UIView beginAnimations:nil context:flakeView];
	//动画持续时间
	[UIView setAnimationDuration:5 * speed];
	//定义图像视图结束时的坐标和尺寸
	flakeView.frame = CGRectMake(endX, 500.0, 25.0 * scale, 25.0 * scale);
	//提交动画
	[UIView commitAnimations];
}

《30天精通iPhone手机编程》-Day25-雪花_第1张图片

你可能感兴趣的:(编程,iPhone,Random,手机,UIView,图形)