一、运用继承,添加自定义的属性
项目:Homework_MoreCircleMove_Teacher0307
1.1
#import <UIKit/UIKit.h>
@interface CustomImageView : UIImageView
//初始角度
@property float startAngle;
@end
1.2 for…in
//2.2 使用泛型遍历for in
for (CustomImageView *earth in earthArray)
{
//给变球的角度
float endAngle = earth.startAngle + speedAngle;
//计算x,y坐标
float x = CENTER_X + REDIOUS * cos(HUDU(endAngle));
float y = CENTER_Y + REDIOUS * sin(HUDU(endAngle));
earth.center = CGPointMake(x, y);
}
二、UIView动画设置雪花下落
项目:Homework_FaillingSnow_Teacher0307
1.1 UIView动画
//1.创建雪花
_snow = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 60, 60)];
_snow.image = [UIImage imageNamed:@"flake"];
[self.window addSubview:_snow];
//2.UIView动画
//a.开启一个动画块儿
//void * :代表任意指针
[UIView beginAnimations:nil context:nil];
//a.1 设置动画时间,秒
[UIView setAnimationDuration:3];
//a.2 设置动画要运动的位置坐标
_snow.frame = CGRectMake(100, 400, 60, 60);
//a.3 设置动画结束的方法
//a.3.1 设置代理,让谁来执行动画结束的方法
[UIView setAnimationDelegate:self];
//a.3.2 设置动画结束时的方法
[UIView setAnimationDidStopSelector:@selector(snowChangeAlpha)];
//b.提交动画
[UIView commitAnimations];
1.2 结束动画
//改变透明度
- (void)snowChangeAlpha
{
//a.3 设置透明度变化,取值范围是0~1。
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
// //RGB:[0,255]
// [UIColor colorWithRed:180.0/255.0 green:34.0/255.0 blue:120.0/255.0 alpha:1];
_snow.alpha = 0;
//方法1:代理
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(removeSnow)];
//方法2:延迟执行方法
//当代码执行到这一句代码时,会延迟*秒再执行@selector(removeSnow:)方法
//方法参数类型 与 所传对象(object)类型 保持一致
[self performSelector:@selector(removeSnow:) withObject:_snow afterDelay:1];
[UIView commitAnimations];
}
//移除雪花
- (void)removeSnow:(UIImageView *)snow
{
[snow removeFromSuperview];
}