Skip to content

Commit

Permalink
Merge pull request #2 from TalkingJourney/develop
Browse files Browse the repository at this point in the history
解决事件冲突问题
  • Loading branch information
自由流水 authored Jan 14, 2018
2 parents 43e85bc + 3a6b241 commit cde5335
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
17 changes: 15 additions & 2 deletions SCIndexView/SCIndexView.m
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,23 @@ - (void)onActionWithDidSelect

- (void)onActionWithScroll
{
if (self.isTouchingIndexView) {
// 当滑动tableView视图时,另一手指滑动索引视图,让tableView滑动失效
self.tableView.panGestureRecognizer.enabled = NO;
self.tableView.panGestureRecognizer.enabled = YES;

return; // 当滑动索引视图时,tableView滚动不能影响索引位置
}

// 可能tableView的contentOffset变化,却没有scroll,此时不应该影响索引位置
BOOL isScrolling = self.tableView.isDragging || self.tableView.isDecelerating;
if (!isScrolling) return;

if (self.delegate && [self.delegate respondsToSelector:@selector(sectionOfIndexView:tableViewDidScroll:)]) {
self.currentSection = [self.delegate sectionOfIndexView:self tableViewDidScroll:self.tableView];
return;
}

if (self.isTouchingIndexView) return;

NSIndexPath *needIndexPath;
if (!self.translucentForTableViewInNavigationBar) {
needIndexPath = self.tableView.indexPathsForVisibleRows.firstObject;
Expand Down Expand Up @@ -246,6 +256,9 @@ - (void)refreshTextLayer:(BOOL)selected

- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
{
// 当滑动索引视图时,防止其他手指去触发事件
if (self.touchingIndexView) return YES;

CATextLayer *firstTextLayer = self.subTextLayers.firstObject;
if (!firstTextLayer) return NO;
CATextLayer *lastTextLayer = self.subTextLayers.lastObject;
Expand Down
11 changes: 11 additions & 0 deletions SCIndexViewDemo/SCIndexViewDemo/SCIndexViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ - (void)viewDidLoad {
default:
break;
}
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(onActionWithRightBarButton)];

self.translucent = YES;

Expand Down Expand Up @@ -97,6 +98,16 @@ - (void)indexView:(SCIndexView *)indexView didSelectAtIndex:(NSUInteger)index

}

#pragma mark - Event Response

- (void)onActionWithRightBarButton
{
UIViewController *viewController = [UIViewController new];
viewController.view.backgroundColor = [UIColor whiteColor];
viewController.title = @"分享";
[self.navigationController pushViewController:viewController animated:YES];
}

#pragma mark - Getter and Setter

- (UITableView *)tableView
Expand Down

0 comments on commit cde5335

Please sign in to comment.