Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ DerivedData
.idea/
/TSTableView
/TSTabView
/.project
/.gitignore
28 changes: 20 additions & 8 deletions Classes/TSUIKit/TSTableView/Private/TSTableViewContentHolder.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#import "TSUtils.h"
#import "TSDefines.h"



/**
@abstract Selection rectangle view
Expand Down Expand Up @@ -77,6 +77,17 @@ - (void)initialize
[self addSubview:_imageView];

self.selectionColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:0.25f];

//mark: add hide TSTableViewSelection event
UITapGestureRecognizer *hideEvent = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleHide:)];
[self addGestureRecognizer:hideEvent];
}

- (void)handleHide:(UITapGestureRecognizer *)recognizer
{
self.alpha = 0;
self.hidden = YES;
self.selectedItem = nil;
}

- (void)setSelectionColor:(UIColor *)selectionColor
Expand All @@ -103,8 +114,6 @@ @interface TSTableViewContentHolder ()
@property (nonatomic, strong) TSTableViewSelection *rowSelectionView;
@property (nonatomic, strong) TSTableViewSelection *columnSelectionView;

@property (nonatomic, strong) UITapGestureRecognizer *tapGestureRecognizer;

@end

@implementation TSTableViewContentHolder
Expand Down Expand Up @@ -164,8 +173,9 @@ - (void)initialize
_reusableCells = [[NSMutableDictionary alloc] init];
_reusableRows = [[NSMutableArray alloc] init];

_tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGestureDidRecognized:)];
[self addGestureRecognizer:_tapGestureRecognizer];
//mark: remove TSTableViewContentHolder's tapGestureRecognizer
// _tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGestureDidRecognized:)];
// [self addGestureRecognizer:_tapGestureRecognizer];
}

- (TSTableViewSelection *)rowSelectionView
Expand Down Expand Up @@ -390,8 +400,9 @@ - (void)updateRowsVisibility
(topTreshold <= CGRectGetMaxY(row.frame) && CGRectGetMaxY(row.frame) <= bottomTreshold) ||
(CGRectGetMinY(row.frame) < topTreshold && bottomTreshold < CGRectGetMaxY(row.frame)))
{
if(!row.rowView)
if(!row.rowView){
[self rowWillAppear:row atPath:[NSIndexPath indexPathWithIndex:i]];
}
}
else
{
Expand Down Expand Up @@ -782,12 +793,13 @@ - (NSIndexPath *)pathToSelectedColumn
}

#pragma mark - Selection

- (void)tapGestureDidRecognized:(UITapGestureRecognizer *)recognizer
//mark: 响应左侧面板的点击事件
- (void)tapExpandPanelRecognized:(UITapGestureRecognizer *)recognizer
{
if(_allowRowSelection)
{
CGPoint pos = [recognizer locationInView:self];
pos.x += self.frame.origin.x;//mark: 把事件发生的点偏移一个左侧面板宽度的距离
NSIndexPath *rowIndexPath = [self findRowAtPosition:pos parentRow:nil parentPowPath:nil];

if(rowIndexPath)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#import "TSUtils.h"
#import "TSDefines.h"


@interface TSTableViewExpandControlPanel ()
{
NSMutableArray* _rows;
Expand Down Expand Up @@ -116,8 +115,9 @@ - (void)addExpandButtonAtPath:(NSIndexPath *)rowPath expandRowView:(TSTableViewE
UIImage *normalImage = [self.dataSource controlPanelExpandItemNormalBackgroundImage];
UIImage *selectedImage = [self.dataSource controlPanelExpandItemSelectedBackgroundImage];
CGFloat rowHeight = [self.dataSource heightForRowAtPath:rowPath];
UIButton *expandBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, expandRow.frame.size.width, rowHeight)];
expandBtn.autoresizingMask = UIViewAutoresizingFlexibleWidth;
UIButton *expandBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 24, rowHeight)];
// expandBtn.backgroundColor = [UIColor colorWithRed:0 green:0.8 blue:0 alpha:0.3];
// expandBtn.autoresizingMask = UIViewAutoresizingFlexibleWidth;
expandBtn.showsTouchWhenHighlighted = [self.dataSource highlightControlsOnTap];
expandBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
expandBtn.contentVerticalAlignment = UIControlContentVerticalAlignmentBottom;
Expand Down Expand Up @@ -168,7 +168,7 @@ - (void)loadSubrowsForRowAtPath:(NSIndexPath *)rowPath expandRowView:(TSTableVie
NSInteger numberOfRows = [self.dataSource numberOfRowsAtPath:rowPath];
if(numberOfRows)
{
CGFloat controlPanelExpandButtonWidth = [self.dataSource widthForExpandItem];
CGFloat controlPanelExpandButtonWidth = [self.dataSource widthForExpandItem];//此宽度决定行头内容显示的宽度
UIImage *controlPanelExpandBackImage = [self.dataSource controlPanelExpandSectionBackgroundImage];
NSMutableArray *newRows = [[NSMutableArray alloc] init];
for(int j = 0; j < numberOfRows; ++j)
Expand All @@ -192,6 +192,16 @@ - (void)loadSubrowsForRowAtPath:(NSIndexPath *)rowPath expandRowView:(TSTableVie
rowView.lineLabel.textColor = [self.dataSource lineNumbersColor];
}
[self addExpandButtonAtPath:subrowPath expandRowView:rowView];

//mark: 在TSTableViewExpandSection中添加一个label
NSString *rowhead = [self.dataSource rowHead:subrowPath];

//根据计算结果重新设置UILabel的尺寸
CGSize size = [rowhead sizeWithFont:rowView.rowHeadLabel.font constrainedToSize:CGSizeMake(controlPanelExpandButtonWidth, rowView.rowHeadLabel.frame.size.height)];
[rowView.rowHeadLabel setFrame:CGRectMake(rowView.rowHeadLabel.frame.origin.x, rowView.rowHeadLabel.frame.origin.y, size.width, rowView.rowHeadLabel.frame.size.height)];

rowView.rowHeadLabel.text = rowhead;

[self loadSubrowsForRowAtPath:subrowPath expandRowView:rowView];

[newRows addObject:rowView];
Expand Down Expand Up @@ -570,7 +580,8 @@ - (void)updateLayoutForRows:(NSArray *)rows
totalHeight:(CGFloat *)totalHeight
nestingLevel:(NSInteger *)maxNestingLevel
{
CGFloat controlPanelExpandButtonWidth = [self.dataSource widthForExpandItem];
CGFloat controlPanelExpandButtonWidth = [self.dataSource widthForExpandItem];//此宽度决定整个controlPanel的宽度
CGFloat nestingSize = [self.dataSource expandNestingSize];
CGFloat maxWidth = 0;
NSInteger maxNestLevel = 0;
for(int i = 0; i < rows.count; ++i)
Expand All @@ -584,7 +595,7 @@ - (void)updateLayoutForRows:(NSArray *)rows
{
[self updateLayoutForRows:row.subrows
yOffset:totalRowHeight
xOffset:totalRowWidth
xOffset:nestingSize
totalWidth:&totalRowWidth
totalHeight:&totalRowHeight
nestingLevel:&nestingLevel];
Expand All @@ -600,20 +611,20 @@ - (void)updateLayoutForRows:(NSArray *)rows
if(nestingLevel > maxNestLevel)
maxNestLevel = nestingLevel;
}
*totalWidth += maxWidth;
*totalWidth = maxWidth + nestingSize;
*maxNestingLevel += maxNestLevel;
}

- (void)adjustRowWidthTo:(CGFloat)rowWidth forRows:(NSArray *)rows
{
CGFloat controlPanelExpandButtonWidth = [self.dataSource widthForExpandItem];
CGFloat nestingSize = [self.dataSource expandNestingSize];
for(int i = 0; i < rows.count; ++i)
{
TSTableViewExpandSection *row = rows[i];
row.frame = CGRectMake(row.frame.origin.x, row.frame.origin.y, rowWidth, row.frame.size.height);
if(row.subrows.count)
{
[self adjustRowWidthTo:rowWidth - controlPanelExpandButtonWidth forRows:row.subrows];
[self adjustRowWidthTo:rowWidth - nestingSize forRows:row.subrows];
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
@property (nonatomic, strong) UIButton *expandButton;
@property (nonatomic, strong, readonly) UILabel *lineLabel;
@property (nonatomic, strong, readonly) UIImageView *backgroundImage;
@property (nonatomic, strong, readonly) UILabel *rowHeadLabel;

- (void)setLineNumber:(NSInteger)lineNumber;

Expand Down
32 changes: 30 additions & 2 deletions Classes/TSUIKit/TSTableView/Private/TSTableViewExpandSection.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ @interface TSTableViewExpandSection ()

@property (nonatomic, strong, readwrite) UILabel *lineLabel;
@property (nonatomic, strong, readwrite) UIImageView *backgroundImage;

@property (nonatomic, strong, readwrite) UILabel *rowHeadLabel;

@end

Expand Down Expand Up @@ -69,7 +69,7 @@ - (UILabel *)lineLabel
_lineLabel.backgroundColor = [UIColor colorWithWhite:0 alpha:0.1f];
_lineLabel.textAlignment = NSTextAlignmentCenter;
_lineLabel.textColor = [UIColor blackColor];
_lineLabel.font = [UIFont italicSystemFontOfSize:7];
_lineLabel.font = [UIFont italicSystemFontOfSize:6.5];
_lineLabel.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin;
_lineLabel.layer.cornerRadius = 3;
_lineLabel.layer.masksToBounds = YES;
Expand All @@ -79,6 +79,25 @@ - (UILabel *)lineLabel
return _lineLabel;
}

- (UILabel *)rowHeadLabel
{
if(!_rowHeadLabel)
{
_rowHeadLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0,self.bounds.size.width, _rowHeight)];
_rowHeadLabel.backgroundColor = [UIColor clearColor];
_rowHeadLabel.font = [UIFont systemFontOfSize:14.0f];
_rowHeadLabel.textColor = [UIColor darkGrayColor];

// _rowHeadLabel.textAlignment = NSTextAlignmentCenter;
// _rowHeadLabel.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin;
// _rowHeadLabel.layer.cornerRadius = 3;
// _rowHeadLabel.layer.masksToBounds = YES;
[self addSubview:_rowHeadLabel];
[self updateRowHeadLabelLayout];
}
return _rowHeadLabel;
}

- (UIImageView *)backgroundImage
{
if(!_backgroundImage)
Expand Down Expand Up @@ -112,6 +131,15 @@ - (void)updateLineLabelLayout
}
}

- (void)updateRowHeadLabelLayout
{
if(_rowHeadLabel)
{
// [self.rowHeadLabel sizeThatFits:CGSizeMake(200, 20)];
self.rowHeadLabel.frame = CGRectMake(25, 0, self.rowHeadLabel.frame.size.width + 40, self.rowHeadLabel.frame.size.height);
}
}

- (void)setExpandButton:(UIButton *)expandButton
{
if(_expandButton)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
#import "TSUtils.h"
#import "TSDefines.h"


@interface TSTableViewHeaderPanel ()
{
NSMutableArray *_headerSections;
Expand Down
Loading