From f7232fdadda191c778c7da0cb14eb78c4e8bd8a2 Mon Sep 17 00:00:00 2001 From: Sunny Wang Date: Sun, 9 Aug 2015 10:14:57 -0400 Subject: [PATCH 1/3] iCarousel accessibility support (two categories) --- .../project.pbxproj | 6 + .../project.pbxproj | 6 + .../iCarouselExampleViewController.m | 5 + iCarousel/iCarousel+AccessibilityScrolling.h | 12 ++ iCarousel/iCarousel+AccessibilityScrolling.m | 60 +++++++++ iCarousel/iCarousel+AccessiblityButtons.h | 14 +++ iCarousel/iCarousel+AccessiblityButtons.m | 116 ++++++++++++++++++ iCarousel/iCarousel.h | 3 + iCarousel/iCarousel.m | 32 ++++- 9 files changed, 249 insertions(+), 5 deletions(-) create mode 100644 iCarousel/iCarousel+AccessibilityScrolling.h create mode 100644 iCarousel/iCarousel+AccessibilityScrolling.m create mode 100644 iCarousel/iCarousel+AccessiblityButtons.h create mode 100644 iCarousel/iCarousel+AccessiblityButtons.m mode change 100644 => 100755 iCarousel/iCarousel.h mode change 100644 => 100755 iCarousel/iCarousel.m diff --git a/Examples/Advanced iOS Demo/iCarouselExample.xcodeproj/project.pbxproj b/Examples/Advanced iOS Demo/iCarouselExample.xcodeproj/project.pbxproj index dcb497567b..37b6b42a21 100644 --- a/Examples/Advanced iOS Demo/iCarouselExample.xcodeproj/project.pbxproj +++ b/Examples/Advanced iOS Demo/iCarouselExample.xcodeproj/project.pbxproj @@ -17,6 +17,7 @@ 0148359513A36C3700E687AC /* MainWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 0148358F13A36C3700E687AC /* MainWindow.xib */; }; 0148359613A36C3700E687AC /* iCarouselExampleViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 0148359113A36C3700E687AC /* iCarouselExampleViewController.xib */; }; 018AE98A179D7EBA00FB7311 /* Default-568h@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 018AE989179D7EBA00FB7311 /* Default-568h@2x.png */; }; + 1D59A4501B37AEC70092AB37 /* iCarousel+AccessibilityScrolling.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D59A44F1B37AEC70092AB37 /* iCarousel+AccessibilityScrolling.m */; }; B2E5E6C1146145C900EADB7A /* iCarousel.m in Sources */ = {isa = PBXBuildFile; fileRef = B2E5E6C0146145C900EADB7A /* iCarousel.m */; }; B2E5E72D1461544B00EADB7A /* background.png in Resources */ = {isa = PBXBuildFile; fileRef = B2E5E72B1461544B00EADB7A /* background.png */; }; B2E5E72E1461544B00EADB7A /* page.png in Resources */ = {isa = PBXBuildFile; fileRef = B2E5E72C1461544B00EADB7A /* page.png */; }; @@ -39,6 +40,8 @@ 0148359213A36C3700E687AC /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/iCarouselExampleViewController.xib; sourceTree = SOURCE_ROOT; }; 018AE989179D7EBA00FB7311 /* Default-568h@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default-568h@2x.png"; sourceTree = SOURCE_ROOT; }; 018BBCB413A375AF005CA505 /* iCarouselExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = iCarouselExample.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 1D59A44E1B37AEC70092AB37 /* iCarousel+AccessibilityScrolling.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "iCarousel+AccessibilityScrolling.h"; sourceTree = ""; }; + 1D59A44F1B37AEC70092AB37 /* iCarousel+AccessibilityScrolling.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "iCarousel+AccessibilityScrolling.m"; sourceTree = ""; }; B2E5E6BF146145C900EADB7A /* iCarousel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = iCarousel.h; sourceTree = ""; }; B2E5E6C0146145C900EADB7A /* iCarousel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = iCarousel.m; sourceTree = ""; }; B2E5E72B1461544B00EADB7A /* background.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = background.png; path = ../Resources/background.png; sourceTree = SOURCE_ROOT; }; @@ -121,6 +124,8 @@ children = ( B2E5E6BF146145C900EADB7A /* iCarousel.h */, B2E5E6C0146145C900EADB7A /* iCarousel.m */, + 1D59A44E1B37AEC70092AB37 /* iCarousel+AccessibilityScrolling.h */, + 1D59A44F1B37AEC70092AB37 /* iCarousel+AccessibilityScrolling.m */, ); name = iCarousel; path = ../../iCarousel; @@ -201,6 +206,7 @@ buildActionMask = 2147483647; files = ( 0148358813A36C2000E687AC /* main.m in Sources */, + 1D59A4501B37AEC70092AB37 /* iCarousel+AccessibilityScrolling.m in Sources */, 0148359313A36C3700E687AC /* iCarouselExampleViewController.m in Sources */, 0148359413A36C3700E687AC /* iCarouselExampleAppDelegate.m in Sources */, B2E5E6C1146145C900EADB7A /* iCarousel.m in Sources */, diff --git a/Examples/Paging Example/iCarouselExample.xcodeproj/project.pbxproj b/Examples/Paging Example/iCarouselExample.xcodeproj/project.pbxproj index fa7dd962b2..ce4357ba40 100644 --- a/Examples/Paging Example/iCarouselExample.xcodeproj/project.pbxproj +++ b/Examples/Paging Example/iCarouselExample.xcodeproj/project.pbxproj @@ -17,6 +17,7 @@ 0148359413A36C3700E687AC /* iCarouselExampleAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 0148358D13A36C3700E687AC /* iCarouselExampleAppDelegate.m */; }; 0148359513A36C3700E687AC /* MainWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 0148358F13A36C3700E687AC /* MainWindow.xib */; }; 0148359613A36C3700E687AC /* iCarouselExampleViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 0148359113A36C3700E687AC /* iCarouselExampleViewController.xib */; }; + 1D39196B1B77995700798841 /* iCarousel+AccessiblityButtons.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D39196A1B77995700798841 /* iCarousel+AccessiblityButtons.m */; }; B2E5E6C1146145C900EADB7A /* iCarousel.m in Sources */ = {isa = PBXBuildFile; fileRef = B2E5E6C0146145C900EADB7A /* iCarousel.m */; }; /* End PBXBuildFile section */ @@ -37,6 +38,8 @@ 0148359013A36C3700E687AC /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/MainWindow.xib; sourceTree = SOURCE_ROOT; }; 0148359213A36C3700E687AC /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/iCarouselExampleViewController.xib; sourceTree = SOURCE_ROOT; }; 018BBCB413A375AF005CA505 /* iCarouselExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = iCarouselExample.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 1D3919691B77995700798841 /* iCarousel+AccessiblityButtons.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "iCarousel+AccessiblityButtons.h"; sourceTree = ""; }; + 1D39196A1B77995700798841 /* iCarousel+AccessiblityButtons.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "iCarousel+AccessiblityButtons.m"; sourceTree = ""; }; B2E5E6BF146145C900EADB7A /* iCarousel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = iCarousel.h; sourceTree = ""; }; B2E5E6C0146145C900EADB7A /* iCarousel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = iCarousel.m; sourceTree = ""; }; /* End PBXFileReference section */ @@ -116,6 +119,8 @@ children = ( B2E5E6BF146145C900EADB7A /* iCarousel.h */, B2E5E6C0146145C900EADB7A /* iCarousel.m */, + 1D3919691B77995700798841 /* iCarousel+AccessiblityButtons.h */, + 1D39196A1B77995700798841 /* iCarousel+AccessiblityButtons.m */, ); name = iCarousel; path = ../../iCarousel; @@ -187,6 +192,7 @@ 0148358813A36C2000E687AC /* main.m in Sources */, 0148359313A36C3700E687AC /* iCarouselExampleViewController.m in Sources */, 0148359413A36C3700E687AC /* iCarouselExampleAppDelegate.m in Sources */, + 1D39196B1B77995700798841 /* iCarousel+AccessiblityButtons.m in Sources */, B2E5E6C1146145C900EADB7A /* iCarousel.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/Examples/Paging Example/iCarouselExampleViewController.m b/Examples/Paging Example/iCarouselExampleViewController.m index 2424ba2c2b..3f966d5719 100644 --- a/Examples/Paging Example/iCarouselExampleViewController.m +++ b/Examples/Paging Example/iCarouselExampleViewController.m @@ -121,4 +121,9 @@ - (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSInteger)index r return view; } +- (NSString *)accessibilityAnnoucement:(NSInteger)index isForwarded:(BOOL)forwarded{ + NSString *announcement = [NSString stringWithFormat:@"%@, Page %ld of %ld", forwarded ? @"Scrolling Forward" : @"Scrolling Backward", (long)index, (long)_items.count]; + return announcement; +} + @end diff --git a/iCarousel/iCarousel+AccessibilityScrolling.h b/iCarousel/iCarousel+AccessibilityScrolling.h new file mode 100644 index 0000000000..6da6ceb243 --- /dev/null +++ b/iCarousel/iCarousel+AccessibilityScrolling.h @@ -0,0 +1,12 @@ +// +// iCarousel+Accessibility.h +// CardCompanion +// +// Created by Wang, Jinlian(Sunny) on 5/29/15. +// + +#import "iCarousel.h" + +@interface iCarousel (AccessibilityScrolling) + +@end diff --git a/iCarousel/iCarousel+AccessibilityScrolling.m b/iCarousel/iCarousel+AccessibilityScrolling.m new file mode 100644 index 0000000000..0ee211d628 --- /dev/null +++ b/iCarousel/iCarousel+AccessibilityScrolling.m @@ -0,0 +1,60 @@ +// +// iCarousel+Accessibility.m +// CardCompanion +// +// Created by Wang, Jinlian(Sunny) on 5/29/15. +// + +#import "iCarousel+AccessibilityScrolling.h" + +@implementation iCarousel (AccessibilityScrolling) + +- (void)setUpAccessiblity{ + //Need UIAccessibilityTraitCausesPageTurn flag to announce hint if iCarousel is made to be accessibible + self.accessibilityTraits = self.accessibilityTraits | UIAccessibilityTraitCausesPageTurn; +} + +-(BOOL)accessibilityScroll:(UIAccessibilityScrollDirection)direction{ + BOOL result = YES; + switch (direction) { + case UIAccessibilityScrollDirectionNext: + case UIAccessibilityScrollDirectionRight: + if(self.currentItemIndex > 0){ + [self scrollToItemAtIndex:(self.currentItemIndex-1) animated:YES completionHandler:^(NSInteger index){ + NSString *announcement = [self accessibilityAnnouncement:index isForwarded:NO]; + UIAccessibilityPostNotification(UIAccessibilityPageScrolledNotification, announcement); + }]; + } else { + result = NO; + } + break; + case UIAccessibilityScrollDirectionPrevious: + case UIAccessibilityScrollDirectionLeft: + if(self.currentItemIndex < (self.numberOfItems-1)){ + [self scrollToItemAtIndex:(self.currentItemIndex+1) animated:YES completionHandler:^(NSInteger index){ + NSString *announcement = [self accessibilityAnnouncement:index isForwarded:YES]; + UIAccessibilityPostNotification(UIAccessibilityPageScrolledNotification, announcement); + }]; + } else { + result = NO; + } + break; + case UIAccessibilityScrollDirectionUp: + case UIAccessibilityScrollDirectionDown: + result = NO; + break; + } + return result; +} + +-(NSString *)accessibilityAnnouncement:(NSInteger)index isForwarded:(BOOL)forwarded{ + NSString *announcement = nil; + __strong id delegate = self.delegate; + if([delegate respondsToSelector:@selector(accessibilityAnnoucement:isForwarded:)]){ + announcement = [delegate accessibilityAnnoucement:index isForwarded:forwarded]; + } + announcement = announcement ? announcement: [NSString stringWithFormat:@"Item %ld", (long) index]; + return announcement; +} + +@end diff --git a/iCarousel/iCarousel+AccessiblityButtons.h b/iCarousel/iCarousel+AccessiblityButtons.h new file mode 100644 index 0000000000..0b1f61e745 --- /dev/null +++ b/iCarousel/iCarousel+AccessiblityButtons.h @@ -0,0 +1,14 @@ +// +// iCarousel+AccessiblityButtons.h +// CardCompanion +// +// Created by Wang, Jinlian(Sunny) on 5/29/15. +// + +#import "iCarousel.h" + +@interface iCarousel (AccessiblityButtons) + +@property (nonatomic, strong) id auxiliaryButtons; + +@end diff --git a/iCarousel/iCarousel+AccessiblityButtons.m b/iCarousel/iCarousel+AccessiblityButtons.m new file mode 100644 index 0000000000..94fcf370fb --- /dev/null +++ b/iCarousel/iCarousel+AccessiblityButtons.m @@ -0,0 +1,116 @@ +// +// iCarousel+AccessiblityButtons.m +// CardCompanion +// +// Created by Wang, Jinlian(Sunny) on 5/29/15. +// + +#import +#import "iCarousel+AccessiblityButtons.h" +#import "iCarousel.h" + +#define BUTTON_WIDTH 50 + +@interface iCarousel (accessibilityAuxiliaryViews) + +@end + +@implementation iCarousel (AccessiblityButtons) +@dynamic auxiliaryButtons; + +-(BOOL)isAccessibilityElement{ + return NO; +} + +-(void)setUpAccessiblity{ + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(voiceOverChanged:) name:UIAccessibilityVoiceOverStatusChanged object:nil]; + [self handleVoiceOverStatusChange]; +} + +-(void)cleanUpAccessibility{ + [[NSNotificationCenter defaultCenter] removeObserver:self name:UIAccessibilityVoiceOverStatusChanged object:nil]; +} + +-(void)voiceOverChanged:(NSNotification *)notification { + [self handleVoiceOverStatusChange]; +} + +-(void)handleVoiceOverStatusChange{ + if(UIAccessibilityIsVoiceOverRunning() && !self.auxiliaryButtons){ + [self setupAuxiliaryButtons]; + } + + NSArray *array = (NSArray *)self.auxiliaryButtons; + [array enumerateObjectsUsingBlock:^(UIView *button, NSUInteger index, BOOL *stop){ + button.hidden = !UIAccessibilityIsVoiceOverRunning(); + }]; +} + + +- (void)setAuxiliaryButtons:(id)array { + objc_setAssociatedObject(self, @selector(auxiliaryButtons), array, OBJC_ASSOCIATION_RETAIN_NONATOMIC); +} + +- (id)auxiliaryButtons { + return objc_getAssociatedObject(self, @selector(auxiliaryButtons)); +} + +-(void)setupAuxiliaryButtons{ + NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:2]; + UIButton *forwardButton = [UIButton buttonWithType:UIButtonTypeCustom]; + forwardButton.accessibilityLabel = @"Scroll Forward"; + [forwardButton setTitle: @"\u2329" forState: UIControlStateNormal]; + forwardButton.accessibilityTraits = forwardButton.accessibilityTraits | UIAccessibilityTraitStartsMediaSession; + forwardButton.backgroundColor = [UIColor colorWithWhite:0.7f alpha:0.7]; + [forwardButton addTarget:self action:@selector(forwardButtonTapped:) forControlEvents:UIControlEventTouchUpInside]; + [self addSubview:forwardButton]; + forwardButton.translatesAutoresizingMaskIntoConstraints = NO; + NSDictionary *viewsDictionary = NSDictionaryOfVariableBindings(forwardButton); + [self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[forwardButton]-0-|" options:0 metrics:nil views:viewsDictionary]]; + [self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"|-0-[forwardButton(50)]" options:0 metrics:nil views:viewsDictionary]]; + [array addObject:forwardButton]; + + UIButton *backwardButton = [UIButton buttonWithType:UIButtonTypeCustom]; + backwardButton.accessibilityLabel = @"Scroll Backward"; + backwardButton.accessibilityTraits = backwardButton.accessibilityTraits | UIAccessibilityTraitStartsMediaSession; + [backwardButton setTitle: @"\u232a" forState: UIControlStateNormal]; + backwardButton.backgroundColor = [UIColor colorWithWhite:0.7f alpha:0.7]; + [backwardButton addTarget:self action:@selector(backwardButtonTapped:) forControlEvents:UIControlEventTouchUpInside]; + [self addSubview:backwardButton]; + backwardButton.translatesAutoresizingMaskIntoConstraints = NO; + viewsDictionary = NSDictionaryOfVariableBindings(backwardButton); + [self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[backwardButton]-0-|" options:0 metrics:nil views:viewsDictionary]]; + [self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"[backwardButton(50)]-0-|" options:0 metrics:nil views:viewsDictionary]]; + [array addObject:backwardButton]; + + self.auxiliaryButtons = array; +} + +-(void)forwardButtonTapped:(id)sender{ + if(self.currentItemIndex > 0){ + [self scrollToItemAtIndex:(self.currentItemIndex-1) animated:YES completionHandler:^(NSInteger index){ + NSString *announcement = [self accessibilityAnnouncement:index isForwarded:YES]; + UIAccessibilityPostNotification(UIAccessibilityPageScrolledNotification, announcement); + }]; + } +} + +-(void)backwardButtonTapped:(id)sender{ + if(self.currentItemIndex < (self.numberOfItems -1)){ + [self scrollToItemAtIndex:(self.currentItemIndex+1) animated:YES completionHandler:^(NSInteger index){ + NSString *announcement = [self accessibilityAnnouncement:index isForwarded:NO]; + UIAccessibilityPostNotification(UIAccessibilityPageScrolledNotification,announcement); + }]; + } +} + +-(NSString *)accessibilityAnnouncement:(NSInteger)index isForwarded:(BOOL)forwarded{ + NSString *announcement = nil; + if([self.delegate respondsToSelector:@selector(accessibilityAnnoucement:isForwarded:)]){ + announcement = [self.delegate accessibilityAnnoucement:index isForwarded:forwarded]; + } + announcement = announcement ? announcement: [NSString stringWithFormat:@"Item %ld", (long) index]; + return announcement; +} + +@end diff --git a/iCarousel/iCarousel.h b/iCarousel/iCarousel.h old mode 100644 new mode 100755 index 53350915d1..aca299192c --- a/iCarousel/iCarousel.h +++ b/iCarousel/iCarousel.h @@ -143,6 +143,7 @@ typedef NS_ENUM(NSInteger, iCarouselOption) - (void)scrollByNumberOfItems:(NSInteger)itemCount duration:(NSTimeInterval)duration; - (void)scrollToItemAtIndex:(NSInteger)index duration:(NSTimeInterval)duration; - (void)scrollToItemAtIndex:(NSInteger)index animated:(BOOL)animated; +- (void)scrollToItemAtIndex:(NSInteger)index animated:(BOOL)animated completionHandler:(void (^)(NSInteger currentItemIndex))completionHandler; - (UIView *)itemViewAtIndex:(NSInteger)index; - (NSInteger)indexOfItemView:(UIView *)view; @@ -191,6 +192,8 @@ typedef NS_ENUM(NSInteger, iCarouselOption) - (CATransform3D)carousel:(iCarousel *)carousel itemTransformForOffset:(CGFloat)offset baseTransform:(CATransform3D)transform; - (CGFloat)carousel:(iCarousel *)carousel valueForOption:(iCarouselOption)option withDefault:(CGFloat)value; +- (NSString *)accessibilityAnnoucement:(NSInteger)index isForwarded:(BOOL)forwarded; + @end #pragma GCC diagnostic pop diff --git a/iCarousel/iCarousel.m b/iCarousel/iCarousel.m old mode 100644 new mode 100755 index be33a13f1a..96825770f4 --- a/iCarousel/iCarousel.m +++ b/iCarousel/iCarousel.m @@ -121,6 +121,7 @@ @interface iCarousel () @property (nonatomic, assign, getter = isDragging) BOOL dragging; @property (nonatomic, assign) BOOL didDrag; @property (nonatomic, assign) NSTimeInterval toggleTime; +@property (nonatomic, copy) void (^completionHandler)(NSInteger currentItemIndex); NSComparisonResult compareViewDepth(UIView *view1, UIView *view2, iCarousel *self); @@ -165,10 +166,6 @@ - (void)setUp tapGesture.delegate = (id )self; [_contentView addGestureRecognizer:tapGesture]; - //set up accessibility - self.accessibilityTraits = UIAccessibilityTraitAllowsDirectInteraction; - self.isAccessibilityElement = YES; - #else [_contentView setWantsLayer:YES]; @@ -181,6 +178,19 @@ - (void)setUp { [self reloadData]; } + + //set up accessibility + if([self respondsToSelector:@selector(setUpAccessiblity)]){ + [self performSelector:@selector(setUpAccessiblity)]; + } +} + +-(void) setUpAccessiblity{ + //leave the implementation to the accessibility category or subclass +} + +-(void) cleanUpAccessiblity{ + //leave the implementation to the accessibility category or subclass } #ifndef USING_CHAMELEON @@ -219,7 +229,10 @@ - (id)initWithFrame:(NSRect)frame } - (void)dealloc -{ +{ + if([self respondsToSelector:@selector(cleanUpAccessiblity)]){ + [self performSelector:@selector(cleanUpAccessiblity)]; + } [self stopAnimation]; } @@ -1495,6 +1508,11 @@ - (void)scrollToItemAtIndex:(NSInteger)index animated:(BOOL)animated [self scrollToItemAtIndex:index duration:animated? SCROLL_DURATION: 0]; } +- (void)scrollToItemAtIndex:(NSInteger)index animated:(BOOL)animated completionHandler:(void (^)(NSInteger currentItemIndex))completionHandler{ + self.completionHandler = completionHandler; + [self scrollToItemAtIndex:index animated:animated]; +} + - (void)removeItemAtIndex:(NSInteger)index animated:(BOOL)animated { index = [self clampedIndex:index]; @@ -1764,6 +1782,10 @@ - (void)step _scrolling = NO; [self depthSortViews]; [self pushAnimationState:YES]; + if(self.completionHandler){ + self.completionHandler(self.currentItemIndex); + self.completionHandler = nil; + } [_delegate carouselDidEndScrollingAnimation:self]; [self popAnimationState]; } From d045b056dcb05c064690ca987997be60ef3ad039 Mon Sep 17 00:00:00 2001 From: Sunny Wang Date: Sun, 9 Aug 2015 22:00:33 -0400 Subject: [PATCH 2/3] Forgot this line to handle the animated = NO case. --- iCarousel/iCarousel.m | 3 +++ 1 file changed, 3 insertions(+) diff --git a/iCarousel/iCarousel.m b/iCarousel/iCarousel.m index 94b58ec7db..ccca8ed4cb 100755 --- a/iCarousel/iCarousel.m +++ b/iCarousel/iCarousel.m @@ -1511,6 +1511,9 @@ - (void)scrollToItemAtIndex:(NSInteger)index animated:(BOOL)animated - (void)scrollToItemAtIndex:(NSInteger)index animated:(BOOL)animated completionHandler:(void (^)(NSInteger currentItemIndex))completionHandler{ self.completionHandler = completionHandler; [self scrollToItemAtIndex:index animated:animated]; + if(!animated){ + completionHandler(self.currentItemIndex); + } } - (void)removeItemAtIndex:(NSInteger)index animated:(BOOL)animated From 731f5ee86ee978a02617b7557255bf925ec859ff Mon Sep 17 00:00:00 2001 From: Sunny Wang Date: Sun, 9 Aug 2015 22:58:51 -0400 Subject: [PATCH 3/3] Forgot this line to handle the animated = NO case-2. --- iCarousel/iCarousel.m | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/iCarousel/iCarousel.m b/iCarousel/iCarousel.m index ccca8ed4cb..93365e8dac 100755 --- a/iCarousel/iCarousel.m +++ b/iCarousel/iCarousel.m @@ -1509,7 +1509,9 @@ - (void)scrollToItemAtIndex:(NSInteger)index animated:(BOOL)animated } - (void)scrollToItemAtIndex:(NSInteger)index animated:(BOOL)animated completionHandler:(void (^)(NSInteger currentItemIndex))completionHandler{ - self.completionHandler = completionHandler; + if(animated){ + self.completionHandler = completionHandler; + } [self scrollToItemAtIndex:index animated:animated]; if(!animated){ completionHandler(self.currentItemIndex);