I'm trying to swizzle the UIScrollView that 3D Touch's peek and pop preview is embedded in. (I know it's a UIScrollView through the Reveal app.)
I want to know whenever the user moves their finger on this scroll view/on the 3D touch preview.
I tried swizzling it as follows:
+ (void)load {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
Class class = [self class];
SEL originalSelector = @selector(setContentOffset:);
SEL swizzledSelector = @selector(xxx_setContentOffset:);
Method originalMethod = class_getInstanceMethod(class, originalSelector);
Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector);
BOOL didAddMethod =
class_addMethod(class,
originalSelector,
method_getImplementation(swizzledMethod),
method_getTypeEncoding(swizzledMethod));
if (didAddMethod) {
class_replaceMethod(class,
swizzledSelector,
method_getImplementation(originalMethod),
method_getTypeEncoding(originalMethod));
} else {
method_exchangeImplementations(originalMethod, swizzledMethod);
}
});
}
#pragma mark - Method Swizzling
- (void)xxx_setContentOffset:(CGPoint)offset {
[self xxx_setContentOffset:offset];
NSLog(@"yes");
}
But it only calls "yes" once or twice when there should be hundreds of calls from sliding my finger across the screen.
Am I swizzling this wrong?