From 92addfe0e712956ece0f86a7f76474b44519c191 Mon Sep 17 00:00:00 2001 From: David Benko Date: Wed, 14 May 2014 16:25:16 -0400 Subject: [PATCH 1/3] Fix to orientation change drawing issues removes old columns before drawing new ones in layoutSubviews: --- KLScrollSelect/KLScrollSelect/KLScrollSelect.m | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/KLScrollSelect/KLScrollSelect/KLScrollSelect.m b/KLScrollSelect/KLScrollSelect/KLScrollSelect.m index dd854cc..36d6044 100644 --- a/KLScrollSelect/KLScrollSelect/KLScrollSelect.m +++ b/KLScrollSelect/KLScrollSelect/KLScrollSelect.m @@ -71,6 +71,11 @@ -(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]; @@ -428,4 +433,4 @@ -(NSInteger) row return self->_innerIndexPath.row; } -@end \ No newline at end of file +@end From b77907a311e0649d6d14b7c033dc344f22b7ea33 Mon Sep 17 00:00:00 2001 From: David Benko Date: Wed, 28 May 2014 11:07:45 -0400 Subject: [PATCH 2/3] Added autoScrollingEnabled property --- KLScrollSelect/KLScrollSelect/KLScrollSelect.h | 1 + KLScrollSelect/KLScrollSelect/KLScrollSelect.m | 17 ++++++++++++----- .../KLScrollSelectDemo/KLViewController.m | 1 + 3 files changed, 14 insertions(+), 5 deletions(-) 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 36d6044..c9eade5 100644 --- a/KLScrollSelect/KLScrollSelect/KLScrollSelect.m +++ b/KLScrollSelect/KLScrollSelect/KLScrollSelect.m @@ -49,6 +49,8 @@ -(void) updateDriverOffset; -(BOOL) animating; @end @implementation KLScrollSelect +@synthesize autoScrollEnabled; + -(BOOL) animating { return (BOOL)self.animationTimer; } @@ -63,8 +65,9 @@ -(NSArray*) columnsWithoutColumn:(KLScrollingColumn*) column { -(void) layoutSubviews { [super layoutSubviews]; [self populateColumns]; - [self startScrollingDriver]; - + if (self.autoScrollEnabled) { + [self startScrollingDriver]; + } } -(void) synchronizeColumnsForMainDriver { @@ -164,16 +167,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]; } } diff --git a/KLScrollSelectDemo/KLScrollSelectDemo/KLViewController.m b/KLScrollSelectDemo/KLScrollSelectDemo/KLViewController.m index 4b48687..0de3341 100644 --- a/KLScrollSelectDemo/KLScrollSelectDemo/KLViewController.m +++ b/KLScrollSelectDemo/KLScrollSelectDemo/KLViewController.m @@ -19,6 +19,7 @@ -(void) viewDidLoad { self.scrollSelect = [[KLScrollSelect alloc] initWithFrame: CGRectMake(0, 150, 320, 438)]; [self.scrollSelect setDataSource: self]; [self.scrollSelect setDelegate: self]; + [self.scrollSelect setAutoScrollEnabled:NO]; [self.scrollSelect setBackgroundColor:[UIColor clearColor]]; [self.view addSubview: self.scrollSelect]; From 9b9ab35c377e25f3856632e0741effb6b9f769b6 Mon Sep 17 00:00:00 2001 From: David Benko Date: Wed, 28 May 2014 17:35:58 -0400 Subject: [PATCH 3/3] Remove @synthesize and set autoscroll to true by default --- KLScrollSelect/KLScrollSelect/KLScrollSelect.m | 11 ++++++++++- .../KLScrollSelectDemo/KLViewController.m | 2 -- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/KLScrollSelect/KLScrollSelect/KLScrollSelect.m b/KLScrollSelect/KLScrollSelect/KLScrollSelect.m index c9eade5..992525b 100644 --- a/KLScrollSelect/KLScrollSelect/KLScrollSelect.m +++ b/KLScrollSelect/KLScrollSelect/KLScrollSelect.m @@ -49,7 +49,16 @@ -(void) updateDriverOffset; -(BOOL) animating; @end @implementation KLScrollSelect -@synthesize autoScrollEnabled; + +- (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; diff --git a/KLScrollSelectDemo/KLScrollSelectDemo/KLViewController.m b/KLScrollSelectDemo/KLScrollSelectDemo/KLViewController.m index 0de3341..f4df12b 100644 --- a/KLScrollSelectDemo/KLScrollSelectDemo/KLViewController.m +++ b/KLScrollSelectDemo/KLScrollSelectDemo/KLViewController.m @@ -19,8 +19,6 @@ -(void) viewDidLoad { self.scrollSelect = [[KLScrollSelect alloc] initWithFrame: CGRectMake(0, 150, 320, 438)]; [self.scrollSelect setDataSource: self]; [self.scrollSelect setDelegate: self]; - [self.scrollSelect setAutoScrollEnabled:NO]; - [self.scrollSelect setBackgroundColor:[UIColor clearColor]]; [self.view addSubview: self.scrollSelect];