Permalink
Browse files

new init methode

  • Loading branch information...
1 parent 72625ec commit 9fd2710ac022f17062c4dfccd78b7478f4450d17 @many20 committed Apr 14, 2012
@@ -37,16 +37,19 @@
NSString *cachedNibName;
NSArray *cacheAlternativeViewArray;
+
+ NSArray *dontAddSubviewsFromThisClasses;
}
@property (nonatomic, unsafe_unretained) UIView *layoutView;
@property (nonatomic, strong, readonly) NSString* currentLayout;
@property (nonatomic) BOOL nibCaching;
-@property (nonatomic) BOOL baseView;
+@property (nonatomic) BOOL withBaseView;
- (id)init;
-- (id)initLayoutWithName:(NSString *)layoutName fromView:(UIView *)view withBaseView:(BOOL)_baseView;
+- (id)initLayoutWithName:(NSString *)layoutName fromView:(UIView *)view withBaseView:(BOOL)baseView;
+- (id)initLayoutWithName:(NSString *)layoutName fromView:(UIView *)view withBaseView:(BOOL)baseView dontAddSubviewsFromThisClasses:(NSArray *)classes;
- (void)clear;
- (void)clearCache;
@@ -46,7 +46,7 @@ @implementation MALayoutManager
@synthesize currentLayout;
@synthesize nibCaching;
-@synthesize baseView;
+@synthesize withBaseView;
- (id)init {
if((self = [super init])) {
@@ -55,30 +55,39 @@ - (id)init {
currentLayout = @"";
cachedNibName = @"";
nibCaching = NO;
- baseView = NO;
+ withBaseView = NO;
+
+ dontAddSubviewsFromThisClasses = nil;
}
return self;
}
-- (id)initLayoutWithName:(NSString *)layoutName fromView:(UIView *)view withBaseView:(BOOL)_baseView {
+- (id)initLayoutWithName:(NSString *)layoutName fromView:(UIView *)view withBaseView:(BOOL)baseView {
assert(view != nil && layoutName != nil);
if((self = [super init])) {
self.layoutView = view;
layouts = [[NSMutableDictionary alloc] initWithCapacity:2];
currentLayout = @"";
cachedNibName = @"";
nibCaching = NO;
- baseView = NO;
+ withBaseView = NO;
if(view != nil) {
- baseView = _baseView;
+ withBaseView = baseView;
[self addLayoutWithName:layoutName fromView:view];
}
}
return self;
}
+- (id)initLayoutWithName:(NSString *)layoutName fromView:(UIView *)view withBaseView:(BOOL)baseView dontAddSubviewsFromThisClasses:(NSArray *)classes {
+ dontAddSubviewsFromThisClasses = classes;
+
+ return [self initLayoutWithName:layoutName fromView:view withBaseView:baseView];
+}
+
+
//### public methods
- (void)clear {
@@ -101,7 +110,7 @@ - (void)addLayoutWithName:(NSString *)layoutName fromView:(UIView *)view {
NSMutableDictionary *layoutDictionary = [NSMutableDictionary dictionary];
[layouts setObject:layoutDictionary forKey:layoutName];
- if (baseView == YES) {
+ if (withBaseView == YES) {
[self addLayoutFromView:view toDictionary:layoutDictionary];
} else {
for (UIView *subview in view.subviews) {
@@ -140,7 +149,7 @@ - (void)addLayoutWithName:(NSString *)layoutName fromNib:(NSString *)nib withInd
NSMutableDictionary *layoutDictionary = [NSMutableDictionary dictionary];
[layouts setObject:layoutDictionary forKey:layoutName];
- if (baseView == YES) {
+ if (withBaseView == YES) {
[self addLayoutFromAlternativeView:alternativeView forView:self.layoutView toDictionary:layoutDictionary];
} else {
UIView *alternativeViewSubview = nil;
@@ -239,9 +248,9 @@ - (bool)isValid {
- (bool)changeToLayoutWithName:(NSString *)layoutName {
assert([self isValid] == YES);
- if (currentLayout == layoutName) {
+ /*if (currentLayout == layoutName) {
return NO;
- }
+ }*/
NSMutableDictionary *layoutDictionary = [layouts objectForKey:layoutName];
if (layoutDictionary == nil || self.layoutView == nil) {
@@ -317,11 +326,18 @@ - (void)addLayoutFromView:(UIView *)view toDictionary:(NSMutableDictionary *)dic
[dictionary setObject:config forKey:[NSNumber numberWithInt:(int)view]];
+ //UIButtons option "Shows touch on hightlight" uses a extra View, that makes problems.
+ for (Class class in dontAddSubviewsFromThisClasses) {
+ if([view isMemberOfClass:class] == YES) {
+ return;
+ }
+ }
+
for (int i = 0; i < [view.subviews count]; i++) {
UIView *subview = [view.subviews objectAtIndex:i];
- [self addLayoutFromView:subview toDictionary:dictionary];
- }
+ [self addLayoutFromView:subview toDictionary:dictionary];
+ }
}
- (void)addLayoutFromAlternativeView:(UIView *)alternativeView forView:(UIView *)view toDictionary:(NSMutableDictionary *)dictionary {
@@ -341,11 +357,18 @@ - (void)addLayoutFromAlternativeView:(UIView *)alternativeView forView:(UIView *
//NSMutableDictionary *tmp = [dictionary objectForKey:[NSNumber numberWithInt:(int)view]];
//NSLog(@"%@", NSStringFromCGRect([[tmp objectForKey:@"frame"]CGRectValue]));
- for (int i = 0; i < view.subviews.count; i++) {
- UIView *subview = [view.subviews objectAtIndex:i];
+ //UIButtons option "Shows touch on hightlight" uses a extra View, that makes problems.
+ for (Class class in dontAddSubviewsFromThisClasses) {
+ if([view isMemberOfClass:class] == YES) {
+ return;
+ }
+ }
+
+ for (int i = 0; i < view.subviews.count; i++) {
+ UIView *subview = [view.subviews objectAtIndex:i];
UIView *alternativeSubview = [alternativeView.subviews objectAtIndex:i];
- [self addLayoutFromAlternativeView:alternativeSubview forView:subview toDictionary:dictionary];
+ [self addLayoutFromAlternativeView:alternativeSubview forView:subview toDictionary:dictionary];
}
}
//Test
@@ -32,7 +32,7 @@ - (void)viewDidLoad
{
[super viewDidLoad];
- layoutManager = [[MALayoutManager alloc] initLayoutWithName:@"portraiLayout1" fromView:self.view withBaseView:NO];
+ layoutManager = [[MALayoutManager alloc] initLayoutWithName:@"portraiLayout1" fromView:self.view withBaseView:NO dontAddSubviewsFromThisClasses:[NSArray arrayWithObjects:UIButton.class, nil]];
[layoutManager addLayoutWithName:@"landscapeLayout1" fromNib:@"ViewController_iPhone_layout2"];
[layoutManager addLayoutWithName:@"portraiLayout2" fromView:self.view];
@@ -57,7 +57,7 @@ - (void)viewDidLoad
- //### Testes
+ //### Tests
/*
newView1 = [[UIView alloc] initWithFrame:CGRectMake(CGRectGetMidX([[UIScreen mainScreen] applicationFrame]), CGRectGetMidY([[UIScreen mainScreen] applicationFrame]), 100, 100)];

0 comments on commit 9fd2710

Please sign in to comment.