From a177cb4aca3fe4362bae78c872c0cb561c10248c Mon Sep 17 00:00:00 2001 From: Stony Wang Date: Thu, 18 Apr 2013 15:00:49 +0800 Subject: [PATCH 1/5] add findbytag --- CSLinearLayoutView/CSLinearLayoutView.h | 1 + CSLinearLayoutView/CSLinearLayoutView.m | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/CSLinearLayoutView/CSLinearLayoutView.h b/CSLinearLayoutView/CSLinearLayoutView.h index b0e160b..6ce47ec 100644 --- a/CSLinearLayoutView/CSLinearLayoutView.h +++ b/CSLinearLayoutView/CSLinearLayoutView.h @@ -58,6 +58,7 @@ typedef enum { - (void)swapItem:(CSLinearLayoutItem *)firstItem withItem:(CSLinearLayoutItem *)secondItem; +- (CSLinearLayoutItem*)findItemByTag:(NSInteger)tag; @end diff --git a/CSLinearLayoutView/CSLinearLayoutView.m b/CSLinearLayoutView/CSLinearLayoutView.m index 94dcef1..0367174 100644 --- a/CSLinearLayoutView/CSLinearLayoutView.m +++ b/CSLinearLayoutView/CSLinearLayoutView.m @@ -323,6 +323,16 @@ - (void)swapItem:(CSLinearLayoutItem *)firstItem withItem:(CSLinearLayoutItem *) [self setNeedsLayout]; } +- (CSLinearLayoutItem*)findItemByTag:(NSInteger)tag +{ + for (CSLinearLayoutItem *item in _items) { + if (item.tag == tag) { + return item; + } + } + return nil; +} + @end #pragma mark - From 41656a5f1671885527c2dbc6aa62219200002f29 Mon Sep 17 00:00:00 2001 From: Stony Wang Date: Thu, 18 Apr 2013 15:16:39 +0800 Subject: [PATCH 2/5] add tag assign --- CSLinearLayoutView/CSLinearLayoutView.m | 1 + 1 file changed, 1 insertion(+) diff --git a/CSLinearLayoutView/CSLinearLayoutView.m b/CSLinearLayoutView/CSLinearLayoutView.m index 0367174..3e74bed 100644 --- a/CSLinearLayoutView/CSLinearLayoutView.m +++ b/CSLinearLayoutView/CSLinearLayoutView.m @@ -363,6 +363,7 @@ - (id)initWithView:(UIView *)aView { self = [super init]; if (self) { self.view = aView; + self.tag = aView.tag; self.horizontalAlignment = CSLinearLayoutItemHorizontalAlignmentLeft; self.verticalAlignment = CSLinearLayoutItemVerticalAlignmentTop; self.fillMode = CSLinearLayoutItemFillModeNormal; From 462ddadb8fe30a73fe4ef8910ba1ee345482169a Mon Sep 17 00:00:00 2001 From: Stony Wang Date: Wed, 3 Jul 2013 14:46:19 +0800 Subject: [PATCH 3/5] ARC --- CSLinearLayoutView/CSLinearLayoutView.h | 4 ++-- CSLinearLayoutView/CSLinearLayoutView.m | 16 ++-------------- 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/CSLinearLayoutView/CSLinearLayoutView.h b/CSLinearLayoutView/CSLinearLayoutView.h index 6ce47ec..25a040a 100644 --- a/CSLinearLayoutView/CSLinearLayoutView.h +++ b/CSLinearLayoutView/CSLinearLayoutView.h @@ -88,12 +88,12 @@ typedef struct { @interface CSLinearLayoutItem : NSObject -@property (nonatomic, retain) UIView *view; +@property (nonatomic, strong) UIView *view; @property (nonatomic, assign) CSLinearLayoutItemFillMode fillMode; @property (nonatomic, assign) CSLinearLayoutItemHorizontalAlignment horizontalAlignment; // Use horizontalAlignment when the layout view is set to VERTICAL orientation @property (nonatomic, assign) CSLinearLayoutItemVerticalAlignment verticalAlignment; // Use verticalAlignment when the layout view is set to HORIZONTAL orientation @property (nonatomic, assign) CSLinearLayoutItemPadding padding; -@property (nonatomic, assign) NSDictionary *userInfo; +@property (nonatomic, weak) NSDictionary *userInfo; @property (nonatomic, assign) NSInteger tag; - (id)initWithView:(UIView *)aView; diff --git a/CSLinearLayoutView/CSLinearLayoutView.m b/CSLinearLayoutView/CSLinearLayoutView.m index 3e74bed..8f0ed42 100644 --- a/CSLinearLayoutView/CSLinearLayoutView.m +++ b/CSLinearLayoutView/CSLinearLayoutView.m @@ -59,10 +59,8 @@ - (void)setup { #pragma mark - Lifecycle - - (void)dealloc { - [_items release], _items = nil; - [super dealloc]; + items = nil; } @@ -210,12 +208,10 @@ - (void)removeItem:(CSLinearLayoutItem *)linearLayoutItem { return; } - [linearLayoutItem retain]; [_items removeObject:linearLayoutItem]; [linearLayoutItem.view removeFromSuperview]; - [linearLayoutItem release]; } - (void)removeAllItems { @@ -264,12 +260,10 @@ - (void)moveItem:(CSLinearLayoutItem *)movingItem beforeItem:(CSLinearLayoutItem return; } - [movingItem retain]; [_items removeObject:movingItem]; NSUInteger existingItemIndex = [_items indexOfObject:existingItem]; [_items insertObject:movingItem atIndex:existingItemIndex]; - [movingItem release]; [self setNeedsLayout]; } @@ -279,7 +273,6 @@ - (void)moveItem:(CSLinearLayoutItem *)movingItem afterItem:(CSLinearLayoutItem return; } - [movingItem retain]; [_items removeObject:movingItem]; if (existingItem == [_items lastObject]) { @@ -288,7 +281,6 @@ - (void)moveItem:(CSLinearLayoutItem *)movingItem afterItem:(CSLinearLayoutItem NSUInteger existingItemIndex = [_items indexOfObject:existingItem]; [_items insertObject:movingItem atIndex:++existingItemIndex]; } - [movingItem release]; [self setNeedsLayout]; } @@ -298,7 +290,6 @@ - (void)moveItem:(CSLinearLayoutItem *)movingItem toIndex:(NSUInteger)index { return; } - [movingItem retain]; [_items removeObject:movingItem]; if (index == ([_items count] - 1)) { @@ -306,7 +297,6 @@ - (void)moveItem:(CSLinearLayoutItem *)movingItem toIndex:(NSUInteger)index { } else { [_items insertObject:movingItem atIndex:index]; } - [movingItem release]; [self setNeedsLayout]; } @@ -372,17 +362,15 @@ - (id)initWithView:(UIView *)aView { } + (CSLinearLayoutItem *)layoutItemForView:(UIView *)aView { - CSLinearLayoutItem *item = [[[CSLinearLayoutItem alloc] initWithView:aView] autorelease]; + CSLinearLayoutItem *item = [[CSLinearLayoutItem alloc] initWithView:aView]; return item; } #pragma mark - Memory Management - (void)dealloc { - self.view = nil; self.userInfo = nil; - [super dealloc]; } From b0c4e61c473ce5bd8476e97385c6a59790b71d32 Mon Sep 17 00:00:00 2001 From: Stony Wang Date: Wed, 3 Jul 2013 16:54:26 +0800 Subject: [PATCH 4/5] fix build error --- CSLinearLayoutView/CSLinearLayoutView.m | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CSLinearLayoutView/CSLinearLayoutView.m b/CSLinearLayoutView/CSLinearLayoutView.m index 8f0ed42..400a859 100644 --- a/CSLinearLayoutView/CSLinearLayoutView.m +++ b/CSLinearLayoutView/CSLinearLayoutView.m @@ -10,6 +10,8 @@ @interface CSLinearLayoutView() +@property (nonatomic, readwrite) NSMutableArray *items; + - (void)setup; - (void)adjustFrameSize; - (void)adjustContentSize; @@ -22,7 +24,6 @@ @implementation CSLinearLayoutView @synthesize orientation = _orientation; @synthesize autoAdjustFrameSize = _autoAdjustFrameSize; @synthesize autoAdjustContentSize = _autoAdjustContentSize; - #pragma mark - Factories - (id)init { @@ -60,7 +61,7 @@ - (void)setup { #pragma mark - Lifecycle - (void)dealloc { - items = nil; + self.items = nil; } From 09d8b9c3def4e9f98156e6760f5d8a7367eaee20 Mon Sep 17 00:00:00 2001 From: Stony Wang Date: Tue, 23 Jul 2013 23:29:49 +0800 Subject: [PATCH 5/5] add hidden support --- CSLinearLayoutView/CSLinearLayoutView.h | 6 ++++++ CSLinearLayoutView/CSLinearLayoutView.m | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/CSLinearLayoutView/CSLinearLayoutView.h b/CSLinearLayoutView/CSLinearLayoutView.h index 25a040a..45a0d32 100644 --- a/CSLinearLayoutView/CSLinearLayoutView.h +++ b/CSLinearLayoutView/CSLinearLayoutView.h @@ -86,12 +86,18 @@ typedef struct { CGFloat right; } CSLinearLayoutItemPadding; +NS_ENUM(NSInteger, CSLinearLayoutItemVisibility) { + CSLinearLayoutItemHidden, // Occupy the frame + CSLinearLayoutItemGone // Missing in the layout +}; + @interface CSLinearLayoutItem : NSObject @property (nonatomic, strong) UIView *view; @property (nonatomic, assign) CSLinearLayoutItemFillMode fillMode; @property (nonatomic, assign) CSLinearLayoutItemHorizontalAlignment horizontalAlignment; // Use horizontalAlignment when the layout view is set to VERTICAL orientation @property (nonatomic, assign) CSLinearLayoutItemVerticalAlignment verticalAlignment; // Use verticalAlignment when the layout view is set to HORIZONTAL orientation +@property (nonatomic, assign) enum CSLinearLayoutItemVisibility hiddenType; // Apply when the layout view is set YES hidden @property (nonatomic, assign) CSLinearLayoutItemPadding padding; @property (nonatomic, weak) NSDictionary *userInfo; @property (nonatomic, assign) NSInteger tag; diff --git a/CSLinearLayoutView/CSLinearLayoutView.m b/CSLinearLayoutView/CSLinearLayoutView.m index 400a859..06deea0 100644 --- a/CSLinearLayoutView/CSLinearLayoutView.m +++ b/CSLinearLayoutView/CSLinearLayoutView.m @@ -74,6 +74,10 @@ - (void)layoutSubviews { for (CSLinearLayoutItem *item in _items) { + if (item.view.hidden && item.hiddenType == CSLinearLayoutItemGone) { + continue; + } + CGFloat startPadding = 0.0; CGFloat endPadding = 0.0; @@ -165,6 +169,10 @@ - (CGFloat)layoutOffset { CGFloat currentOffset = 0.0; for (CSLinearLayoutItem *item in _items) { + if (item.view.hidden && item.hiddenType == CSLinearLayoutItemGone) { + continue; + } + if (_orientation == CSLinearLayoutViewOrientationHorizontal) { currentOffset += item.padding.left + item.view.frame.size.width + item.padding.right; } else {