- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
_window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
_window.backgroundColor = [UIColor whiteColor];
[_window makeKeyAndVisible];
//创建可变数组
mutArray = [[NSMutableArray alloc] initWithCapacity:7];
for (int i=0; i<7; i++) {
//创建子视图
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(60, 200, 250, 250)];
view.backgroundColor = [UIColor colorWithRed:arc4random()%10*0.1 green:arc4random()%10*0.1 blue:arc4random()%10*0.1 alpha:1];
[_window addSubview:view];
//取出数组中的最后一个元素(也就是最上层的视图)
UIView *lastView = [mutArray lastObject];
if (lastView != nil) {
view.transform = CGAffineTransformScale(lastView.transform, .8, .8);
}
//将视图添加到数组中
[mutArray addObject:view];
}
_index = 0;
//开启定时器
[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timeAction:) userInfo:nil repeats:YES];
return YES;
}
- (void)timeAction:(NSTimer *)time {
_index ++;
//取得所有视图进行旋转
for (UIView *view in mutArray) {
//开始动画
[UIView beginAnimations:nil context:nil];
//设置动画的时间
[UIView setAnimationDuration:1];
//设置加速方式
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
view.transform = CGAffineTransformRotate(view.transform, M_PI/1.1);
view.backgroundColor = [UIColor colorWithRed:arc4random()%10*0.1 green:arc4random()%10*0.1 blue:arc4random()%10*0.1 alpha:1];
[UIView commitAnimations];
}
//当第十秒的时候移除视图
if (_index == 10) {
for (UIView *view in mutArray) {
[view removeFromSuperview];
}
}
8797

被折叠的 条评论
为什么被折叠?



