Prepare UX rework:

- Handle tap gesture on the sticky headers
This commit is contained in:
Giom Foret 2017-04-20 17:42:25 +02:00
parent e51e4e891e
commit 8d070784c4

View file

@ -449,9 +449,17 @@
frame = sectionHeader.frame; frame = sectionHeader.frame;
frame.origin.y = 0; frame.origin.y = 0;
sectionHeader.frame = frame; sectionHeader.frame = frame;
sectionHeader.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[self.stickyHeadersTopContainer addSubview:sectionHeader]; [self.stickyHeadersTopContainer addSubview:sectionHeader];
topContainerOffset = sectionHeader.frame.size.height; topContainerOffset = sectionHeader.frame.size.height;
// Handle tap gesture
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onStickyHeaderTap:)];
[tap setNumberOfTouchesRequired:1];
[tap setNumberOfTapsRequired:1];
[tap setDelegate:self];
[sectionHeader addGestureRecognizer:tap];
for (NSUInteger index = 1; index < sectionsCount; index++) for (NSUInteger index = 1; index < sectionsCount; index++)
{ {
sectionHeader = [self tableView:self.recentsTableView viewForStickyHeaderInSection:index]; sectionHeader = [self tableView:self.recentsTableView viewForStickyHeaderInSection:index];
@ -459,22 +467,44 @@
frame = sectionHeader.frame; frame = sectionHeader.frame;
frame.origin.y = topContainerOffset; frame.origin.y = topContainerOffset;
sectionHeader.frame = frame; sectionHeader.frame = frame;
sectionHeader.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[self.stickyHeadersTopContainer addSubview:sectionHeader]; [self.stickyHeadersTopContainer addSubview:sectionHeader];
topContainerOffset += frame.size.height; topContainerOffset += frame.size.height;
// Handle tap gesture
tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onStickyHeaderTap:)];
[tap setNumberOfTouchesRequired:1];
[tap setNumberOfTapsRequired:1];
[tap setDelegate:self];
[sectionHeader addGestureRecognizer:tap];
sectionHeader = [self tableView:self.recentsTableView viewForStickyHeaderInSection:index]; sectionHeader = [self tableView:self.recentsTableView viewForStickyHeaderInSection:index];
sectionHeader.tag = index; sectionHeader.tag = index;
frame = sectionHeader.frame; frame = sectionHeader.frame;
frame.origin.y = bottomContainerOffset; frame.origin.y = bottomContainerOffset;
sectionHeader.frame = frame; sectionHeader.frame = frame;
sectionHeader.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[self.stickyHeadersBottomContainer addSubview:sectionHeader]; [self.stickyHeadersBottomContainer addSubview:sectionHeader];
bottomContainerOffset += frame.size.height; bottomContainerOffset += frame.size.height;
// Handle tap gesture
tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onStickyHeaderTap:)];
[tap setNumberOfTouchesRequired:1];
[tap setNumberOfTapsRequired:1];
[tap setDelegate:self];
[sectionHeader addGestureRecognizer:tap];
} }
[self refreshStickyHeadersContainersHeight]; [self refreshStickyHeadersContainersHeight];
} }
} }
- (void)onStickyHeaderTap:(UIGestureRecognizer*)gestureRecognizer
{
UIView *view = gestureRecognizer.view;
[self.recentsTableView scrollToRowAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:view.tag] atScrollPosition:UITableViewScrollPositionTop animated:YES];
}
- (void)refreshStickyHeadersContainersHeight - (void)refreshStickyHeadersContainersHeight
{ {
if (_enableStickyHeaders) if (_enableStickyHeaders)