Skip to content

Instantly share code, notes, and snippets.

@GregularExpressions
Last active August 29, 2015 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GregularExpressions/10114517 to your computer and use it in GitHub Desktop.
Save GregularExpressions/10114517 to your computer and use it in GitHub Desktop.
UICollectionView subclass overriding touches
- (void) touchesBegan:(NSSet *)touches
withEvent:(UIEvent *)event
{
[super touchesBegan:touches withEvent:event];
UITouch* touch = touches.allObjects.firstObject;
if ([touch.view isKindOfClass:[SupplementaryViewClass class]]) {
SupplementaryViewClass *sectionHeader = (SupplementaryViewClass*)touch.view;
[sectionHeader setHighlighted:YES];
}
}
- (void) touchesEnded:(NSSet *)touches
withEvent:(UIEvent *)event
{
[super touchesEnded:touches withEvent:event];
UITouch* touch = touches.allObjects.firstObject;
if ([touch.view isKindOfClass:[SupplementaryViewClass class]]) {
SupplementaryViewClass* sectionHeader = (SupplementaryViewClass*)touch.view;
[sectionHeader setHighlighted:NO];
// Tell the Parent View Controller that the supplementary view was tapped as I want to push the nav:
if (self.parentViewController &&
[self.parentViewController respondsToSelector:@selector(didSelectSection:)]) {
[self.parentViewController performSelector:@selector(didSelectSection:) withObject:sectionHeader];
}
}
}
- (void) touchesCancelled:(NSSet *)touches
withEvent:(UIEvent *)event
{
[super touchesCancelled:touches withEvent:event];
UITouch* touch = touches.allObjects.firstObject;
if ([touch.view isKindOfClass:[SupplementaryViewClass class]]) {
SupplementaryViewClass* sectionHeader = (SupplementaryViewClass*)touch.view;
[sectionHeader setHighlighted:NO];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment