Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

remove view layout methods and prefix all category method names & pro…

…perties
  • Loading branch information...
commit 2315f5587e4db9bc28deaf6fe1e322c514e1f8d5 1 parent 81aa6fd
@Machx authored
View
2  Rebel/NSObject+RBObjectSizzlingAdditions.h
@@ -10,6 +10,6 @@
@interface NSObject (NSObjectSizzlingAdditions)
-+ (void)swapMethod:(SEL)originalSelector with:(SEL)newSelector;
++ (void)rbl_swapMethod:(SEL)originalSelector with:(SEL)newSelector;
@end
View
2  Rebel/NSObject+RBObjectSizzlingAdditions.m
@@ -12,7 +12,7 @@
@implementation NSObject (NSObjectSizzlingAdditions)
// Shamelessly taken from JAViewController since mine is a bit longer & ties into my other framework methods
-+ (void)swapMethod:(SEL)originalSelector with:(SEL)newSelector
++ (void)rbl_swapMethod:(SEL)originalSelector with:(SEL)newSelector
{
Method originalMethod = class_getInstanceMethod(self, originalSelector);
Method newMethod = class_getInstanceMethod(self, newSelector);
View
6 Rebel/NSView+RBLViewControllerAdditions.h
@@ -10,10 +10,6 @@
@interface NSView (NSView_RBLViewControllerAdditions)
-- (void)layoutSubviews;
-- (void)layoutIfNeeded;
-- (void)setNeedsLayout;
-
-@property (nonatomic, assign) IBOutlet NSViewController *viewController;
+@property (nonatomic, assign) IBOutlet NSViewController *rbl_viewController;
@end
View
121 Rebel/NSView+RBLViewControllerAdditions.m
@@ -12,117 +12,64 @@
#import <objc/runtime.h>
void *kRBLViewControllerKey = &kRBLViewControllerKey;
-void *KRBLViewNeedsLayoutKey = &KRBLViewNeedsLayoutKey;
@implementation NSView (NSView_RBLViewControllerAdditions)
-+ (void)initialize {
- if(self == [NSView class]) {
- [self loadSupportForLayoutSubviews];
- }
-}
-
#pragma mark - ViewController
--(id)viewController {
+-(id)rbl_viewController {
return objc_getAssociatedObject(self, kRBLViewControllerKey);
}
--(void)setViewController:(id)newViewController {
+-(void)setRbl_viewController:(id)newViewController {
[[self class] loadSupportForRBLViewControllers];
- if (self.viewController) {
- NSResponder *controllerNextResponder = [self.viewController nextResponder];
+ if (self.rbl_viewController) {
+ NSResponder *controllerNextResponder = [self.rbl_viewController nextResponder];
[self setNextResponder:controllerNextResponder];
- [self.viewController setNextResponder:nil];
+ [self.rbl_viewController setNextResponder:nil];
}
objc_setAssociatedObject(self, kRBLViewControllerKey, newViewController, OBJC_ASSOCIATION_ASSIGN);
if (newViewController) {
NSResponder *ownResponder = [self nextResponder];
- [self setNextResponder:self.viewController];
- [self.viewController setNextResponder:ownResponder];
+ [self setNextResponder:self.rbl_viewController];
+ [self.rbl_viewController setNextResponder:ownResponder];
}
}
-#pragma mark - Layout
-
-+ (void)loadSupportForLayoutSubviews {
- [self swapMethod:@selector(setBounds:) with:@selector(custom_setBounds:)];
- [self swapMethod:@selector(setFrame:) with:@selector(custom_setFrame:)];
- [self swapMethod:@selector(viewWillDraw) with:@selector(custom_viewWillDraw)];
-}
-
-- (void)custom_setBounds:(NSRect)newBounds {
- [self custom_setBounds:newBounds];
-
- [self setNeedsLayout];
-}
-
-- (void)custom_setFrame:(NSRect)newFrame {
- [self custom_setFrame:newFrame];
-
- [self setNeedsLayout];
-}
-
-- (void)custom_viewWillDraw {
- [self layoutIfNeeded];
-
- [self custom_viewWillDraw];
-}
-
-- (void)layoutIfNeeded {
- if([self needsLayout]) {
- [self layoutSubviews];
- }
-}
-
-- (void)layoutSubviews {
- objc_setAssociatedObject(self, KRBLViewNeedsLayoutKey, nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
-}
-
-- (void)setNeedsLayout {
- objc_setAssociatedObject(self, KRBLViewNeedsLayoutKey, [NSNull null], OBJC_ASSOCIATION_RETAIN_NONATOMIC);
-
- [self setNeedsDisplay:YES];
-}
-
-- (BOOL)needsLayout {
- return objc_getAssociatedObject(self, KRBLViewNeedsLayoutKey) != nil;
-}
-
#pragma mark - View Controller Methods
+(void)loadSupportForRBLViewControllers {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
//swizzle swizzle...
- [self swapMethod:@selector(viewWillMoveToSuperview:) with:@selector(custom_viewWillMoveToSuperview:)];
- [self swapMethod:@selector(viewDidMoveToSuperview) with:@selector(custom_viewDidMoveToSuperview)];
+ [self rbl_swapMethod:@selector(viewWillMoveToSuperview:) with:@selector(custom_viewWillMoveToSuperview:)];
+ [self rbl_swapMethod:@selector(viewDidMoveToSuperview) with:@selector(custom_viewDidMoveToSuperview)];
- [self swapMethod:@selector(viewWillMoveToWindow:) with:@selector(custom_viewWillMoveToWindow:)];
- [self swapMethod:@selector(viewDidMoveToWindow) with:@selector(custom_viewDidMoveToWindow)];
+ [self rbl_swapMethod:@selector(viewWillMoveToWindow:) with:@selector(custom_viewWillMoveToWindow:)];
+ [self rbl_swapMethod:@selector(viewDidMoveToWindow) with:@selector(custom_viewDidMoveToWindow)];
- [self swapMethod:@selector(setNextResponder:) with:@selector(custom_setNextResponder:)];
+ [self rbl_swapMethod:@selector(setNextResponder:) with:@selector(custom_setNextResponder:)];
});
}
- (void)custom_viewWillMoveToSuperview:(NSView *)newSuperview {
[self custom_viewWillMoveToSuperview:newSuperview];
- if ([self.viewController isKindOfClass:[RBLViewController class]]) {
+ if ([self.rbl_viewController isKindOfClass:[RBLViewController class]]) {
if (newSuperview == nil) {
- [(RBLViewController *)self.viewController viewWillBeRemovedFromSuperview];
+ [(RBLViewController *)self.rbl_viewController viewWillBeRemovedFromSuperview];
if ((self.superview != nil) && (self.window != nil)) {
- [(RBLViewController *)self.viewController viewWillDisappear];
+ [(RBLViewController *)self.rbl_viewController viewWillDisappear];
}
} else {
- [(RBLViewController *)self.viewController viewWillMoveToSuperview:newSuperview];
+ [(RBLViewController *)self.rbl_viewController viewWillMoveToSuperview:newSuperview];
if (self.window != nil) {
- [(RBLViewController *)self.viewController viewWillAppear];
+ [(RBLViewController *)self.rbl_viewController viewWillAppear];
}
}
}
@@ -131,18 +78,18 @@ - (void)custom_viewWillMoveToSuperview:(NSView *)newSuperview {
- (void)custom_viewDidMoveToSuperview {
[self custom_viewDidMoveToSuperview];
- if ([self.viewController isKindOfClass:[RBLViewController class]]) {
+ if ([self.rbl_viewController isKindOfClass:[RBLViewController class]]) {
if (self.superview == nil) {
- [(RBLViewController *)self.viewController viewWasRemovedFromSuperview];
+ [(RBLViewController *)self.rbl_viewController viewWasRemovedFromSuperview];
if (self.window == nil) {
- [(RBLViewController *)self.viewController viewDidDisappear];
+ [(RBLViewController *)self.rbl_viewController viewDidDisappear];
}
} else {
- [(RBLViewController *)self.viewController viewDidMoveToSuperview];
+ [(RBLViewController *)self.rbl_viewController viewDidMoveToSuperview];
if (self.window != nil) {
- [(RBLViewController *)self.viewController viewDidAppear];
+ [(RBLViewController *)self.rbl_viewController viewDidAppear];
}
}
}
@@ -151,18 +98,18 @@ - (void)custom_viewDidMoveToSuperview {
- (void)custom_viewWillMoveToWindow:(NSWindow *)newWindow {
[self custom_viewWillMoveToWindow:newWindow];
- if ([self.viewController isKindOfClass:[RBLViewController class]]) {
+ if ([self.rbl_viewController isKindOfClass:[RBLViewController class]]) {
if (newWindow == nil) {
- [(RBLViewController *)self.viewController viewWillBeRemovedFromWindow];
+ [(RBLViewController *)self.rbl_viewController viewWillBeRemovedFromWindow];
if ((self.superview != nil) && (self.window != nil)) {
- [(RBLViewController *)self.viewController viewWillDisappear];
+ [(RBLViewController *)self.rbl_viewController viewWillDisappear];
}
} else {
- [(RBLViewController *)self.viewController viewWillMoveToWindow:newWindow];
+ [(RBLViewController *)self.rbl_viewController viewWillMoveToWindow:newWindow];
if (self.superview != nil) {
- [(RBLViewController *)self.viewController viewWillAppear];
+ [(RBLViewController *)self.rbl_viewController viewWillAppear];
}
}
}
@@ -171,26 +118,26 @@ - (void)custom_viewWillMoveToWindow:(NSWindow *)newWindow {
- (void)custom_viewDidMoveToWindow {
[self custom_viewDidMoveToWindow];
- if ([self.viewController isKindOfClass:[RBLViewController class]]) {
+ if ([self.rbl_viewController isKindOfClass:[RBLViewController class]]) {
if (self.window == nil) {
- [(RBLViewController *)self.viewController viewWasRemovedFromWindow];
+ [(RBLViewController *)self.rbl_viewController viewWasRemovedFromWindow];
if (self.superview == nil) {
- [(RBLViewController *)self.viewController viewDidDisappear];
+ [(RBLViewController *)self.rbl_viewController viewDidDisappear];
}
} else {
- [(RBLViewController *)self.viewController viewDidMoveToWindow];
+ [(RBLViewController *)self.rbl_viewController viewDidMoveToWindow];
if (self.superview != nil) {
- [(RBLViewController *)self.viewController viewDidAppear];
+ [(RBLViewController *)self.rbl_viewController viewDidAppear];
}
}
}
}
- (void)custom_setNextResponder:(NSResponder *)newNextResponder {
- if (self.viewController != nil) {
- [self.viewController setNextResponder:newNextResponder];
+ if (self.rbl_viewController != nil) {
+ [self.rbl_viewController setNextResponder:newNextResponder];
return;
}
View
4 Rebel/RBLViewController.m
@@ -29,7 +29,7 @@ -(void)loadView
-(void)setView:(NSView *)view
{
super.view = view;
- self.view.viewController = self;
+ self.view.rbl_viewController = self;
}
- (void)viewDidLoad
@@ -39,7 +39,7 @@ - (void)viewDidLoad
- (void)viewWillAppear
{
- self.view.needsLayout = YES;
+
}
- (void)viewDidAppear
Please sign in to comment.
Something went wrong with that request. Please try again.