IOS第16天(5,Quartz2D雪花)

***

#import "HMView.h"

@interface HMView()
{
    int count;
}
@property (nonatomic, assign) CGFloat snowY;

@end

@implementation HMView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}

// 加载xib完毕就调用
- (void)awakeFromNib
{
//    [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(setNeedsDisplay) userInfo:nil repeats:YES];
    
    // iphone每秒刷新60次
    // 屏幕刷新的时候就会触发
    CADisplayLink *link = [CADisplayLink displayLinkWithTarget:self selector:@selector(setNeedsDisplay)];
    
    [link addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
}



// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{

    _snowY += 5;
   
    
        UIImage *image = [UIImage imageNamed:@"雪花"];
        [image drawAtPoint:CGPointMake(0, _snowY)];

    // Drawing code
    
    if (_snowY >= 480) {
        _snowY = 0;
    }
}


@end

 

posted @ 2015-09-01 17:10  iso  阅读(124)  评论(0编辑  收藏  举报