diff --git a/KLScrollSelect/KLScrollSelect/KLScrollSelect.h b/KLScrollSelect/KLScrollSelect/KLScrollSelect.h index ce29fd8..db66f5f 100644 --- a/KLScrollSelect/KLScrollSelect/KLScrollSelect.h +++ b/KLScrollSelect/KLScrollSelect/KLScrollSelect.h @@ -39,6 +39,7 @@ @property (nonatomic, strong) NSArray* columns; @property (nonatomic, weak) IBOutlet id dataSource; @property (nonatomic, weak) IBOutlet id 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; diff --git a/KLScrollSelect/KLScrollSelect/KLScrollSelect.m b/KLScrollSelect/KLScrollSelect/KLScrollSelect.m index dd854cc..992525b 100644 --- a/KLScrollSelect/KLScrollSelect/KLScrollSelect.m +++ b/KLScrollSelect/KLScrollSelect/KLScrollSelect.m @@ -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; } @@ -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]; @@ -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]; } } @@ -428,4 +449,4 @@ -(NSInteger) row return self->_innerIndexPath.row; } -@end \ No newline at end of file +@end diff --git a/KLScrollSelectDemo/KLScrollSelectDemo/KLViewController.m b/KLScrollSelectDemo/KLScrollSelectDemo/KLViewController.m index 4b48687..f4df12b 100644 --- a/KLScrollSelectDemo/KLScrollSelectDemo/KLViewController.m +++ b/KLScrollSelectDemo/KLScrollSelectDemo/KLViewController.m @@ -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];