Created
October 5, 2012 14:11
-
-
Save adamgit/3839993 to your computer and use it in GitHub Desktop.
VCLoadApplication method swizzle
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
@implementation UIView (swizzled) | |
-(void) swizzledSetNeedsDisplay | |
{ | |
//if( _currentFrame != _lastDrawnFrame ) | |
{ | |
//[super setNeedsDisplay]; | |
} | |
} | |
@end | |
@implementation VCLoadApplication | |
/** Mike Ash's suggested class swizzling function */ | |
void Swizzle(Class c, SEL orig, SEL new) | |
{ | |
Method origMethod = class_getInstanceMethod(c, orig); | |
Method newMethod = class_getInstanceMethod(c, new); | |
if(class_addMethod(c, orig, method_getImplementation(newMethod), method_getTypeEncoding(newMethod))) | |
class_replaceMethod(c, new, method_getImplementation(origMethod), method_getTypeEncoding(origMethod)); | |
else | |
method_exchangeImplementations(origMethod, newMethod); | |
} | |
- (void)viewDidLoad | |
{ | |
[super viewDidLoad]; | |
// Do any additional setup after loading the view. | |
} | |
- (void)viewDidUnload | |
{ | |
[super viewDidUnload]; | |
// Release any retained subviews of the main view. | |
} | |
-(void)viewDidAppear:(BOOL)animated | |
{ | |
/** patch the sprite's to change their setNeedsDisplay */ | |
int numClasses = objc_getClassList(NULL, 0); | |
Class *classes = NULL; | |
classes = malloc(sizeof(Class) * numClasses); | |
numClasses = objc_getClassList(classes, numClasses); | |
NSMutableArray *result = [NSMutableArray array]; | |
for (NSInteger i = 0; i < numClasses; i++) | |
{ | |
Class nextClass = classes[i]; | |
NSString* className = [nextClass description]; | |
if( [className hasSuffix:@"SpriteBase"] ) | |
{ | |
// swizzle it | |
NSLog(@"[%@] Swizzling class: %@", [self class], className ); | |
Swizzle( nextClass, @selector(setNeedsDisplay), <#SEL new#>) | |
} | |
} | |
free(classes); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment