Last active
November 22, 2020 18:13
-
-
Save username0x0a/e6b9cfcd76bc201bc32db0393596e307 to your computer and use it in GitHub Desktop.
UIScrollView category usable for scrollbar dragging detection.
This file contains hidden or 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
@interface UIScrollView () | |
- (BOOL)_isScrubbing; | |
@end | |
@implementation UIScrollView (ScrollbarDraggingDetect) | |
/// A bit complicated and sophisticated subview introspection to detect whether | |
/// the vertical scroll indicator is “expanded for direct manipulation” (= being | |
/// dragged) using private accessors reads and some clang diagnostics pushing. | |
- (BOOL)isScrollingByDraggingVerticalIndicator | |
{ | |
#pragma clang diagnostic push | |
#pragma clang diagnostic ignored "-Warc-performSelector-leaks" | |
#pragma clang diagnostic ignored "-Wdeprecated-objc-pointer-introspection" | |
if (isIOS13) { | |
SEL sel = NSSelectorFromString([@[@"_", @"verticalScroll", @"Indicator"] componentsJoinedByString:@""]); | |
UIView *indy = nil; | |
if ([self respondsToSelector:sel]) | |
indy = [self performSelector:sel]; | |
NSUInteger expanded = 0; | |
sel = NSSelectorFromString([@[ @"expandedFor", @"Direct", @"Manipulation" ] componentsJoinedByString:@""]); | |
if ([indy respondsToSelector:sel]) | |
expanded = (NSUInteger)[indy performSelector:sel] & 0x1; | |
return expanded > 0; | |
} | |
#pragma clang diagnostic pop | |
return NO; | |
} | |
/// This method states scroll bar dragging (scrubbing) in general. It's a private method though. | |
- (BOOL)isScrubbing | |
{ | |
if ([self respondsToSelector:@selector(_isScrubbing)]) | |
return [self _isScrubbing]; | |
return NO; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment