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
1 change: 1 addition & 0 deletions KLScrollSelect/KLScrollSelect/KLScrollSelect.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
@property (nonatomic, strong) NSArray* columns;
@property (nonatomic, weak) IBOutlet id<KLScrollSelectDataSource> dataSource;
@property (nonatomic, weak) IBOutlet id<KLScrollSelectDelegate> delegate;
@property (nonatomic, assign) BOOL autoScrollEnabled;
- (NSInteger)scrollSelect:(KLScrollSelect *)scrollSelect numberOfRowsInColumnAtIndex:(NSInteger)index;
- (NSInteger)scrollSelect:(KLScrollSelect *)scrollSelect numberOfSectionsInColumnAtIndex:(NSInteger)index;
- (CGFloat) scrollSelect: (KLScrollSelect*) scrollSelect heightForColumnAtIndex: (NSInteger) index;
Expand Down
33 changes: 27 additions & 6 deletions KLScrollSelect/KLScrollSelect/KLScrollSelect.m
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ -(void) updateDriverOffset;
-(BOOL) animating;
@end
@implementation KLScrollSelect

- (id)initWithFrame:(CGRect)frameRect
{
if (!(self = [super initWithFrame:frameRect]))
return nil;

self.autoScrollEnabled = true; //Auto scroll by default

return self;
}

-(BOOL) animating {
return (BOOL)self.animationTimer;
}
Expand All @@ -63,14 +74,20 @@ -(NSArray*) columnsWithoutColumn:(KLScrollingColumn*) column {
-(void) layoutSubviews {
[super layoutSubviews];
[self populateColumns];
[self startScrollingDriver];

if (self.autoScrollEnabled) {
[self startScrollingDriver];
}
}

-(void) synchronizeColumnsForMainDriver {
[self synchronizeContentOffsetsWithDriver: self.driver];
}
-(void) populateColumns {

for(KLScrollingColumn *column in self.columns){
[column removeFromSuperview];
}

NSInteger numberOfColumns = [self numberOfColumnsInScrollSelect:self];
NSMutableArray* columns = [[NSMutableArray alloc] initWithCapacity:numberOfColumns];
CGFloat columnWidth = self.frame.size.width/[self numberOfColumnsInScrollSelect:self];
Expand Down Expand Up @@ -159,16 +176,20 @@ - (void)stopScrollingDriver {
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
//Stop animating driver
[self setDriver: (KLScrollingColumn*) scrollView];
[self stopScrollingDriver];
if (self.autoScrollEnabled) {
[self stopScrollingDriver];
}
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
//Start animating driver
[self startScrollingDriver];
if (self.autoScrollEnabled) {
[self startScrollingDriver];
}
}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
if (!decelerate) {
if (!decelerate && self.autoScrollEnabled) {
[self startScrollingDriver];
}
}
Expand Down Expand Up @@ -428,4 +449,4 @@ -(NSInteger) row
return self->_innerIndexPath.row;
}

@end
@end
1 change: 0 additions & 1 deletion KLScrollSelectDemo/KLScrollSelectDemo/KLViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ -(void) viewDidLoad {
self.scrollSelect = [[KLScrollSelect alloc] initWithFrame: CGRectMake(0, 150, 320, 438)];
[self.scrollSelect setDataSource: self];
[self.scrollSelect setDelegate: self];

[self.scrollSelect setBackgroundColor:[UIColor clearColor]];
[self.view addSubview: self.scrollSelect];

Expand Down