雪花

来源:互联网 发布:js包含字符串 编辑:程序博客网 时间:2024/04/28 18:45
#import "RootView.h"
#import "UIColor+RandomColor.h"

@implementation RootView

- (instancetype)initWithFrame:(CGRect)frame
{
 
   self =[super initWithFrame:frame];
    if (self){
       [self addSubviews];
    }
    returnself;
}

#pragma mark - 添加所有控件
- (void)addSubviews
{
   self.backgroundColor = [UIColor cyanColor];
    
    [NSTimerscheduledTimerWithTimeInterval:0.8 target:selfselector:@selector(dingshiqi1) userInfo:nil repeats:YES];
    
   
    [NSTimerscheduledTimerWithTimeInterval:0.01 target:selfselector:@selector(dingshiqi) userInfo:nil repeats:YES];
    
}

#pragma mark - 下落定时器的实现
- (void)dingshiqi
{
    for (int i =0; i < self.subviews.count; i++) {
       CGRect frame = ((UIView *)self.subviews[i]).frame;
      frame.origin.y++;
      ((UIView *)self.subviews[i]).frame = frame;
    }
}

#pragma mark - 生成定时器的实现
- (void)dingshiqi1
{
    UIView *view= [[UIView alloc] initWithFrame:CGRectMake(random() % 375, random()% 50 + 20, 10, 10)];
   view.backgroundColor = [UIColor randomColor];
   view.layer.cornerRadius = 5;
    [selfaddSubview:view];
    [viewrelease];
    
}

@end
0 0