20160912, 动画, Quartz2D + NSTimer

AnimateView.m 文件



#import "AnimateView.h"

@interface AnimateView()
@property (nonatomic, assign) CGFloat changeY;
@end

@implementation AnimateView

-(void)setChangeY:(CGFloat)changeY {
    _changeY = changeY;
//    [self setNeedsDisplay];       // NSTimer 调用了 这个方法, 就不需 再调用了。
}

-(void)awakeFromNib {
    // view由storyBoard创建出来调用的 方法
    [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(setNeedsDisplay) userInfo:nil repeats:YES];
}

// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
    
//    self.changeY++;
    self.changeY += 20;
    
    UIImage * image = [UIImage imageNamed:@"me.png"];
    [image drawAtPoint:CGPointMake(0, self.changeY)];
    
    
    
    // 构造 重复。
    if (self.changeY > [[UIScreen mainScreen ] bounds].size.height ) {
    
        self.changeY = -10;
        
    
    }
    
    
    
    
    
    
    
}


你可能感兴趣的:(20160912, 动画, Quartz2D + NSTimer)