diff --git a/HMSegmentedControl.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/HMSegmentedControl.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 00000000..18d98100 --- /dev/null +++ b/HMSegmentedControl.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/HMSegmentedControl/HMSegmentedControl.h b/HMSegmentedControl/HMSegmentedControl.h index cea60001..2a408199 100755 --- a/HMSegmentedControl/HMSegmentedControl.h +++ b/HMSegmentedControl/HMSegmentedControl.h @@ -10,7 +10,7 @@ @class HMSegmentedControl; -typedef void (^IndexChangeBlock)(NSInteger index); +typedef void (^IndexChangeBlock)(NSUInteger index, BOOL isChange); typedef NSAttributedString *(^HMTitleFormatterBlock)(HMSegmentedControl *segmentedControl, NSString *title, NSUInteger index, BOOL selected); typedef NS_ENUM(NSInteger, HMSegmentedControlSelectionStyle) { diff --git a/HMSegmentedControl/HMSegmentedControl.m b/HMSegmentedControl/HMSegmentedControl.m index abfcefa1..238eaf69 100755 --- a/HMSegmentedControl/HMSegmentedControl.m +++ b/HMSegmentedControl/HMSegmentedControl.m @@ -804,6 +804,11 @@ - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { // Check if we have to do anything with the touch event if (self.isTouchEnabled) [self setSelectedSegmentIndex:segment animated:self.shouldAnimateUserSelection notify:YES]; + }else { + //Handle the index not changed + if (self.indexChangeBlock) { + self.indexChangeBlock(segment, NO); + } } } } @@ -939,7 +944,7 @@ - (void)notifyForSegmentChangeToIndex:(NSInteger)index { [self sendActionsForControlEvents:UIControlEventValueChanged]; if (self.indexChangeBlock) - self.indexChangeBlock(index); + self.indexChangeBlock(index, YES); } #pragma mark - Styling Support diff --git a/HMSegmentedControlExample/ViewController.m b/HMSegmentedControlExample/ViewController.m index 859e6720..8540e85a 100644 --- a/HMSegmentedControlExample/ViewController.m +++ b/HMSegmentedControlExample/ViewController.m @@ -80,8 +80,8 @@ - (void)viewDidLoad { // Segmented control with more customization and indexChangeBlock HMSegmentedControl *segmentedControl3 = [[HMSegmentedControl alloc] initWithSectionTitles:@[@"One", @"Two", @"Three", @"4", @"Five"]]; [segmentedControl3 setFrame:CGRectMake(0, 180, viewWidth, 50)]; - [segmentedControl3 setIndexChangeBlock:^(NSInteger index) { - NSLog(@"Selected index %ld (via block)", (long)index); + [segmentedControl3 setIndexChangeBlock:^(NSUInteger index, BOOL isChange) { + NSLog(@"Selected index %ld,is changed %d", (long)index,isChange); }]; segmentedControl3.selectionIndicatorHeight = 4.0f; segmentedControl3.backgroundColor = [UIColor colorWithRed:0.1 green:0.4 blue:0.8 alpha:1]; @@ -109,7 +109,7 @@ - (void)viewDidLoad { self.segmentedControl4.tag = 3; __weak typeof(self) weakSelf = self; - [self.segmentedControl4 setIndexChangeBlock:^(NSInteger index) { + [self.segmentedControl4 setIndexChangeBlock:^(NSUInteger index, BOOL isChange) { [weakSelf.scrollView scrollRectToVisible:CGRectMake(viewWidth * index, 0, viewWidth, 200) animated:YES]; }];