Created
June 18, 2012 20:44
-
-
Save ahmattox/2950604 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// AnimatedView.h | |
// | |
// Created by Anthony Mattox on 6/18/12. | |
// Copyright (c) 2012 Friends of The Web. All rights reserved. | |
// | |
#import <UIKit/UIKit.h> | |
@interface ParticleView : UIView { | |
id displayLink; | |
BOOL animating; | |
} | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// AnimatedView.m | |
// | |
// Created by Anthony Mattox on 6/18/12. | |
// Copyright (c) 2012 Friends of The Web. All rights reserved. | |
// | |
#import "ParticleView.h" | |
#import <QuartzCore/QuartzCore.h> | |
@implementation ParticleView | |
- (id) initWithCoder:(NSCoder *) aDecoder { | |
self = [super initWithCoder:aDecoder]; | |
if (self) { | |
animating = NO; | |
} | |
return self; | |
} | |
- (void) awakeFromNib { | |
} | |
#pragma mark - Animating | |
- (void) startAnimating { | |
if (!animating) { | |
displayLink = [NSClassFromString(@"CADisplayLink") displayLinkWithTarget:self selector: @selector(setNeedsDisplay)]; | |
[displayLink setFrameInterval:1]; | |
[displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; | |
animating = YES; | |
} | |
} | |
- (void) stopAnimating { | |
if (animating) { | |
[displayLink invalidate]; | |
displayLink = nil; | |
animating = NO; | |
} | |
} | |
- (void)drawRect:(CGRect)rect { | |
// Drawing Code | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment