我正在尝试调整嵌入 3D Touch 的 peek and pop 预览的 UIScrollView。(我知道它是通过 Reveal 应用程序的 UIScrollView。)
我想知道用户何时在此滚动视图/3D 触摸预览上移动手指。
我尝试按如下方式调整它:
+ (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");
}
但是当我的手指在屏幕上滑动应该有数百个呼叫时,它只会呼叫一次或两次“是”。
我错了吗?