编辑
使用AMScrollingNavbar时遇到的一个Bug
本文访问次数:0

请看下图

scrolling-view-bug

由于CollectionView已经超出了UIViewController.view,所以点击事件无法继续传播,导致蓝色区域无法响应点击事件。
经过测试,发现是因为最下层的UIViewController使用的是UITabBarController,蓝色区域就是UITabBar的高度,解决方法很麻烦,每次打开新的页面之后要将UITabBar的高度设置为0,关闭页面的时候再恢复高度,其中用到了Method Swizzling,代码如下


+(void)swizzlingClassMethod:(SEL)originalSelector toMethod:(SEL)swizzledSelector{

    Class class = object_getClass((id)self);

    Method originalMethod = class_getClassMethod(class, originalSelector);
    Method swizzledMethod = class_getClassMethod(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);
    }

}

+(void)swizzlingInstanceMethod:(SEL)originalSelector toMethod:(SEL)swizzledSelector{
    Class class = [self class];

    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);
    }
}

需要输入验证码才能留言

  • 宗仁 2017/02/19 回复 编辑 删除

    @宗仁    添加评论回复功能以及首页显示最新评论的功能

  • 宗仁 2017/02/19 回复 编辑 删除

    重新写了一个测试项目,没有复现这个问题