Skip to content

Instantly share code, notes, and snippets.

@ahmattox
Created June 18, 2012 20:44
Show Gist options
  • Save ahmattox/2950604 to your computer and use it in GitHub Desktop.
Save ahmattox/2950604 to your computer and use it in GitHub Desktop.
//
// 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
//
// 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