如何使用3D touch peek pop正确调配UIScrollView?

时间:2016-03-31 00:18:52

标签: ios objective-c cocoa-touch method-swizzling swizzle

我试图调配UIScrollView,其中嵌入了3D Touch的窥视和弹出预览。(我知道它是通过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");

}

但它只会打电话给#34;是"一次或两次,当我的手指滑过屏幕时应该有数百个电话。

我是不是错了?

0 个答案:

没有答案