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
24 changes: 24 additions & 0 deletions KNPathTableViewController/KNInfoLabel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// KNInfoLabel.h
// KNPathTableViewControllerDemo
//
// Created by Toan Nguyen Huy on 16/1/12.
// Copyright (c) 2012 Anideo. All rights reserved.
//

#import <UIKit/UIKit.h>

#define KNPathTableFadeInDuration 0.3
#define KNPathTableFadeOutDuration 0.3
#define KNPathTableFadeOutDelay 0.5
#define KNPathTableResizeDuration 0.2
#define KNPathTableSlideInOffset 16.0

@interface KNInfoLabel : UIView{
UIImageView * __bgView;
UILabel * __titleLabel;
}

@property (nonatomic, retain) NSString *title;

@end
59 changes: 59 additions & 0 deletions KNPathTableViewController/KNInfoLabel.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//
// KN__titleLabel.m
// KNPathTableViewControllerDemo
//
// Created by Toan Nguyen Huy on 16/1/12.
// Copyright (c) 2012 Anideo. All rights reserved.
//

#import "KNInfoLabel.h"


@implementation KNInfoLabel

@synthesize title;

- (id)init
{
self = [super initWithFrame:CGRectMake(0, 0, 150, 32)];
if (self) {
__bgView = [[UIImageView alloc] initWithFrame:self.bounds];
UIImage * overlay = [UIImage imageNamed:@"KNTableOverlay"];
__bgView.image = [overlay stretchableImageWithLeftCapWidth:overlay.size.width/2.0
topCapHeight:overlay.size.height/2.0];

[self addSubview:__bgView];

__titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(16, 4, 140, 20)];
__titleLabel.font = [UIFont boldSystemFontOfSize:12];
__titleLabel.textAlignment = UITextAlignmentLeft;
__titleLabel.textColor = [UIColor whiteColor];
__titleLabel.shadowColor = [UIColor blackColor];
__titleLabel.backgroundColor = [UIColor clearColor];
__titleLabel.shadowOffset = CGSizeMake(0, -1);
[self addSubview:__titleLabel];
}
return self;
}

- (NSString *) getTitle{
return __titleLabel.text;
}

- (void) setTitle:(NSString *)newTitle{
if (newTitle) {
__titleLabel.text = newTitle;

CGSize textSize = [newTitle sizeWithFont:__titleLabel.font];
CGSize newSize = CGSizeMake(textSize.width + 35, textSize.height);

self.frame = CGRectMake(-newSize.width,
self.frame.origin.y,
newSize.width,
self.frame.size.height);
__bgView.frame = self.bounds;
}
}


@end
13 changes: 3 additions & 10 deletions KNPathTableViewController/KNPathTableViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,15 @@
//

#import <UIKit/UIKit.h>

#define KNPathTableFadeInDuration 0.3
#define KNPathTableFadeOutDuration 0.3
#define KNPathTableFadeOutDelay 0.5
#define KNPathTableSlideInOffset 16.0
#define KNPathTableOverlayDefaultSize CGSizeMake(150, 32)
#import "KNInfoLabel.h"

@interface KNPathTableViewController : UIViewController <UITableViewDataSource, UITableViewDelegate> {
UIView * __infoPanel;
CGSize __infoPanelSize;
CGRect __infoPanelInitialFrame;
KNInfoLabel * __infoPanel;
CGFloat __initalScrollIndicatorHeight;
UITableView * __tableView;
}

@property (nonatomic,readonly) UIView * infoPanel;
@property (retain) KNInfoLabel * infoPanel;
@property (nonatomic,readonly) UITableView * tableView;

-(id)initWithStyle:(UITableViewStyle)style;
Expand Down
43 changes: 15 additions & 28 deletions KNPathTableViewController/KNPathTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,17 @@ @implementation KNPathTableViewController
#pragma mark - Custom init

-(id)initWithStyle:(UITableViewStyle)style {
if ((self = [self initWithStyle:style infoPanelSize:KNPathTableOverlayDefaultSize])) {
}
return self;
}

-(id)initWithStyle:(UITableViewStyle)style infoPanelSize:(CGSize)size {
if ((self = [super init])) {
if ((self = [self init])) {
// The tableview
__tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:style];
__tableView.delegate = self;
__tableView.dataSource = self;
[self.view addSubview:__tableView];

// The panel
__infoPanelSize = size;
__infoPanelInitialFrame = CGRectMake(-__infoPanelSize.width, 0, __infoPanelSize.width, __infoPanelSize.height);
__infoPanel = [[UIView alloc] initWithFrame:__infoPanelInitialFrame];

// Initialize overlay panel with stretchable background
UIImageView * bg = [[UIImageView alloc] initWithFrame:__infoPanel.bounds];
UIImage * overlay = [UIImage imageNamed:@"KNTableOverlay"];
bg.image = [overlay stretchableImageWithLeftCapWidth:overlay.size.width/2.0 topCapHeight:overlay.size.height/2.0];
[__infoPanel setAlpha:0];
[__infoPanel addSubview:bg];
__infoPanel = [[KNInfoLabel alloc] init];
__infoPanel.title = @"Hehe";
__infoPanel.alpha = 0;
}
return self;
}
Expand Down Expand Up @@ -87,7 +74,7 @@ - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
// Add it to indicator
[self moveInfoPanelToIndicatorView];

// Prepare to slide in
// Prepare to slide in
CGRect f = __infoPanel.frame;
CGRect f2= f;
f2.origin.x += KNPathTableSlideInOffset;
Expand All @@ -97,12 +84,12 @@ - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
[self infoPanelWillAppear:scrollView];
[UIView animateWithDuration:KNPathTableFadeInDuration
animations:^{
__infoPanel.alpha = 1;
__infoPanel.frame = f;
} completion:^(BOOL finished) {
[self infoPanelDidAppear:scrollView];
}];
}
__infoPanel.alpha = 1;
__infoPanel.frame = f;
} completion:^(BOOL finished) {
[self infoPanelDidAppear:scrollView];
}];
}

// If it is waiting to fade out, then maintain position
else if ([__infoPanel superview] == self.view) {
Expand Down Expand Up @@ -160,7 +147,7 @@ -(void)moveInfoPanelToSuperView {

-(void)moveInfoPanelToIndicatorView {
UIView * indicator = [[self.tableView subviews] lastObject];
CGRect f = __infoPanelInitialFrame;
CGRect f = CGRectMake(-__infoPanel.frame.size.width, 0, __infoPanel.frame.size.width, __infoPanel.frame.size.height);
f.origin.y = indicator.frame.size.height/2 - f.size.height/2;
if ([__infoPanel superview]) [__infoPanel removeFromSuperview];
[indicator addSubview:__infoPanel];
Expand Down Expand Up @@ -193,12 +180,12 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}

return cell;
}

Expand Down
22 changes: 6 additions & 16 deletions KNPathTableViewControllerDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,14 @@
376B0CFB14BF18800049756D /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 376B0CF914BF18800049756D /* InfoPlist.strings */; };
376B0CFD14BF18800049756D /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 376B0CFC14BF18800049756D /* main.m */; };
376B0D0114BF18800049756D /* KNAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 376B0D0014BF18800049756D /* KNAppDelegate.m */; };
376B0D0614BF18800049756D /* first.png in Resources */ = {isa = PBXBuildFile; fileRef = 376B0D0514BF18800049756D /* first.png */; };
376B0D0814BF18800049756D /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 376B0D0714BF18800049756D /* [email protected] */; };
376B0D0B14BF18800049756D /* KNSecondViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 376B0D0A14BF18800049756D /* KNSecondViewController.m */; };
376B0D0D14BF18800049756D /* second.png in Resources */ = {isa = PBXBuildFile; fileRef = 376B0D0C14BF18800049756D /* second.png */; };
376B0D0F14BF18800049756D /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 376B0D0E14BF18800049756D /* [email protected] */; };
376B0D1514BF18800049756D /* KNSecondViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 376B0D1314BF18800049756D /* KNSecondViewController.xib */; };
376B0D2814BF1C6A0049756D /* KNPathTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 376B0D2514BF1C6A0049756D /* KNPathTableViewController.m */; };
376B0D2914BF1C6A0049756D /* KNTableOverlay.png in Resources */ = {isa = PBXBuildFile; fileRef = 376B0D2614BF1C6A0049756D /* KNTableOverlay.png */; };
376B0D2A14BF1C6A0049756D /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 376B0D2714BF1C6A0049756D /* [email protected] */; };
376B0D2E14BF1D400049756D /* KNFirstViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 376B0D2D14BF1D3F0049756D /* KNFirstViewController.m */; };
376B0D3814BF54F80049756D /* KNThirdViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 376B0D3714BF54F80049756D /* KNThirdViewController.m */; };
CF84700914C36A980099DEA5 /* KNInfoLabel.m in Sources */ = {isa = PBXBuildFile; fileRef = CF84700814C36A980099DEA5 /* KNInfoLabel.m */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -37,12 +34,8 @@
376B0CFE14BF18800049756D /* KNPathTableViewControllerDemo-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "KNPathTableViewControllerDemo-Prefix.pch"; sourceTree = "<group>"; };
376B0CFF14BF18800049756D /* KNAppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KNAppDelegate.h; sourceTree = "<group>"; };
376B0D0014BF18800049756D /* KNAppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = KNAppDelegate.m; sourceTree = "<group>"; };
376B0D0514BF18800049756D /* first.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = first.png; sourceTree = "<group>"; };
376B0D0714BF18800049756D /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; };
376B0D0914BF18800049756D /* KNSecondViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KNSecondViewController.h; sourceTree = "<group>"; };
376B0D0A14BF18800049756D /* KNSecondViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = KNSecondViewController.m; sourceTree = "<group>"; };
376B0D0C14BF18800049756D /* second.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = second.png; sourceTree = "<group>"; };
376B0D0E14BF18800049756D /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; };
376B0D1414BF18800049756D /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/KNSecondViewController.xib; sourceTree = "<group>"; };
376B0D2414BF1C6A0049756D /* KNPathTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KNPathTableViewController.h; sourceTree = "<group>"; };
376B0D2514BF1C6A0049756D /* KNPathTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KNPathTableViewController.m; sourceTree = "<group>"; };
Expand All @@ -52,6 +45,8 @@
376B0D2D14BF1D3F0049756D /* KNFirstViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KNFirstViewController.m; sourceTree = "<group>"; };
376B0D3614BF54F80049756D /* KNThirdViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KNThirdViewController.h; sourceTree = "<group>"; };
376B0D3714BF54F80049756D /* KNThirdViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KNThirdViewController.m; sourceTree = "<group>"; };
CF84700714C36A980099DEA5 /* KNInfoLabel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KNInfoLabel.h; sourceTree = "<group>"; };
CF84700814C36A980099DEA5 /* KNInfoLabel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KNInfoLabel.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -99,10 +94,6 @@
376B0CF614BF18800049756D /* KNPathTableViewControllerDemo */ = {
isa = PBXGroup;
children = (
376B0D0514BF18800049756D /* first.png */,
376B0D0714BF18800049756D /* [email protected] */,
376B0D0C14BF18800049756D /* second.png */,
376B0D0E14BF18800049756D /* [email protected] */,
376B0CFF14BF18800049756D /* KNAppDelegate.h */,
376B0D0014BF18800049756D /* KNAppDelegate.m */,
376B0D2B14BF1D0F0049756D /* KNFirstViewController.h */,
Expand Down Expand Up @@ -135,6 +126,8 @@
376B0D2514BF1C6A0049756D /* KNPathTableViewController.m */,
376B0D2614BF1C6A0049756D /* KNTableOverlay.png */,
376B0D2714BF1C6A0049756D /* [email protected] */,
CF84700714C36A980099DEA5 /* KNInfoLabel.h */,
CF84700814C36A980099DEA5 /* KNInfoLabel.m */,
);
path = KNPathTableViewController;
sourceTree = "<group>";
Expand Down Expand Up @@ -191,10 +184,6 @@
buildActionMask = 2147483647;
files = (
376B0CFB14BF18800049756D /* InfoPlist.strings in Resources */,
376B0D0614BF18800049756D /* first.png in Resources */,
376B0D0814BF18800049756D /* [email protected] in Resources */,
376B0D0D14BF18800049756D /* second.png in Resources */,
376B0D0F14BF18800049756D /* [email protected] in Resources */,
376B0D1514BF18800049756D /* KNSecondViewController.xib in Resources */,
376B0D2914BF1C6A0049756D /* KNTableOverlay.png in Resources */,
376B0D2A14BF1C6A0049756D /* [email protected] in Resources */,
Expand All @@ -214,6 +203,7 @@
376B0D2814BF1C6A0049756D /* KNPathTableViewController.m in Sources */,
376B0D2E14BF1D400049756D /* KNFirstViewController.m in Sources */,
376B0D3814BF54F80049756D /* KNThirdViewController.m in Sources */,
CF84700914C36A980099DEA5 /* KNInfoLabel.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
1 change: 0 additions & 1 deletion KNPathTableViewControllerDemo/KNFirstViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

@interface KNFirstViewController : KNPathTableViewController {
NSMutableArray * array;
UILabel * infoLabel;
}

@end
24 changes: 14 additions & 10 deletions KNPathTableViewControllerDemo/KNFirstViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,15 @@ -(id)initWithStyle:(UITableViewStyle)style {
// Add a series of number
array = [[NSMutableArray alloc] init];
for (int k=0;k<100;k++) {
[array addObject:[NSString stringWithFormat:@"Test row number %d", k]];
if(k < 30){
[array addObject:[NSString stringWithFormat:@"Row %d", k]];
}
else if(k < 60) {
[array addObject:[NSString stringWithFormat:@"Longer row %d", k]];
}
else {
[array addObject:[NSString stringWithFormat:@"Even longer row %d", k]];
}
}
}
return self;
Expand All @@ -29,23 +37,16 @@ -(id)initWithStyle:(UITableViewStyle)style {

-(void)viewDidLoad {
[super viewDidLoad];
infoLabel = [[UILabel alloc] initWithFrame:CGRectMake(16, 4, 140, 20)];
infoLabel.font = [UIFont boldSystemFontOfSize:12];
infoLabel.textAlignment = UITextAlignmentLeft;
infoLabel.textColor = [UIColor whiteColor];
infoLabel.shadowColor = [UIColor blackColor];
infoLabel.backgroundColor = [UIColor clearColor];
infoLabel.shadowOffset = CGSizeMake(0, 1);

// [self.infoPanel addSubview:infoLabel] // this will not work, too early to add
}

-(void)infoPanelWillAppear:(UIScrollView *)scrollView {
if (![infoLabel superview]) [self.infoPanel addSubview:infoLabel];
}

-(void)infoPanelDidScroll:(UIScrollView *)scrollView atPoint:(CGPoint)point {
NSIndexPath * indexPath = [self.tableView indexPathForRowAtPoint:point];
infoLabel.text = [NSString stringWithFormat:@"Something about %d", indexPath.row];
self.infoPanel.title = [__tableView cellForRowAtIndexPath:indexPath].textLabel.text;
}

#pragma mark - Give table some content
Expand All @@ -66,7 +67,10 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}


cell.textLabel.text = [array objectAtIndex:indexPath.row];


return cell;
}

Expand Down
2 changes: 1 addition & 1 deletion KNPathTableViewControllerDemo/KNThirdViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ -(id)initWithStyle:(UITableViewStyle)style {

-(void)infoPanelDidScroll:(UIScrollView *)scrollView atPoint:(CGPoint)point {
NSIndexPath * indexPath = [self.tableView indexPathForRowAtPoint:point];
infoLabel.text = [NSString stringWithFormat:@"In section %d", indexPath.section+1];
self.infoPanel.title = [NSString stringWithFormat:@"In section %d", indexPath.section+1];
}

#pragma mark - Give table some content
Expand Down
Binary file removed KNPathTableViewControllerDemo/first.png
Binary file not shown.
Binary file removed KNPathTableViewControllerDemo/[email protected]
Binary file not shown.
Binary file removed KNPathTableViewControllerDemo/second.png
Binary file not shown.
Binary file removed KNPathTableViewControllerDemo/[email protected]
Binary file not shown.