Created
September 27, 2024 06:42
-
-
Save evgeniyd/773b208b8c1c9ea17df687031739f247 to your computer and use it in GitHub Desktop.
RecognizeGesturesBetweenScrollViewAndButton
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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