Skip to content

Instantly share code, notes, and snippets.

@evgeniyd
Created September 27, 2024 06:42
Show Gist options
  • Save evgeniyd/773b208b8c1c9ea17df687031739f247 to your computer and use it in GitHub Desktop.
Save evgeniyd/773b208b8c1c9ea17df687031739f247 to your computer and use it in GitHub Desktop.
RecognizeGesturesBetweenScrollViewAndButton
/*
The layout (notice how button is 50% on top of the collection view
while still added to the ContainerView)
|----------------------------------------------------|
| ContainerView |
| ------------------------------------------------ |
| | CollectionView | |
| | ___________ | |
| | | | | |
| -----------------| Button |------------------- |
| | | |
| |__________| |
|____________________________________________________|
*/
@implementation ContainerView {
UICollectionView *_collectionView;
UIControl *_closeButton;
}
- (void)makeUI {
_collectionView = ...
[self addSubview:_collectionView];
// Layout collectionView
_closeButton = [[UIButton alloc] initWithFrame:CGRectZero];
[_closeButton addTarget:self action: @selector(didPressButton)];
[self addSubview:_closeButton];
// Layout button
}
- (void)didPressButton {
// perform actions
}
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
UIView *hitView = [super hitTest:point withEvent:event];
// This passes pan gestures to collection view but cannot handle tap gestures anymore
if (hitView == _closeButton && _collectionView.panGestureRecognizer.state = UIGestureRecognizerStatePossible) {
return _collectionView;
}
return hitView;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment