Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
hook mj_header 添加下拉刷新震动
@implementation UIScrollView (Swizz)

+ (void)load {
    
    SEL originalSelector = @selector(setMj_header:);
    SEL swizzledSelector = @selector(nr_setMj_header:);
    Method originalMethod = class_getInstanceMethod(self.class, originalSelector);
    Method swizzledMethod = class_getInstanceMethod(self.class, swizzledSelector);
    
    BOOL didAddMethod =
    class_addMethod(self.class,
                    originalSelector,
                    method_getImplementation(swizzledMethod),
                    method_getTypeEncoding(swizzledMethod));
    if (didAddMethod) {
        class_replaceMethod(self.class,
                            swizzledSelector,
                            method_getImplementation(originalMethod),
                            method_getTypeEncoding(originalMethod));
    }else {
        method_exchangeImplementations(originalMethod, swizzledMethod);
    }
}

- (void)nr_setMj_header:(MJRefreshHeader *)mj_header {
    
    @weakify(mj_header)
    [RACObserve(mj_header, state) subscribeNext:^(id  _Nullable x) {
        @strongify(mj_header)
        if (mj_header.state == MJRefreshStatePulling) {
            AudioServicesPlaySystemSound(1519);
        }
    }];
    [self nr_setMj_header:mj_header];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.