抽屉使用MCPanelViewController来得很晚

时间:2014-01-22 08:46:54

标签: ios navigation-drawer slidingdrawer

我在iOS应用程序中使用MCPanelViewController绘制左右控制器(因为android有内置控件抽屉)。它运作良好,但它没有带来手势,它来得很晚。如果有人对问题有答案那就太棒了。

这是UIViewController (MCPanelViewControllerInternal)类别中的代码:

- (void)handlePan:(UIPanGestureRecognizer *)pan {
    // initialization for screen edge pan gesture
    if ([pan isKindOfClass:[UIScreenEdgePanGestureRecognizer class]] &&
        pan.state == UIGestureRecognizerStateBegan) {
        __weak UIViewController *controller = objc_getAssociatedObject(pan, &MCPanelViewGesturePresentingViewControllerKey);

        if (!controller) {
            return;
        }

        MCPanelAnimationDirection direction = [objc_getAssociatedObject(pan, &MCPanelViewGestureAnimationDirectionKey) integerValue];
        [self setupController:controller withDirection:direction];

        CGPoint translation = [pan translationInView:pan.view];
        CGFloat width = direction == MCPanelAnimationDirectionLeft ? translation.x : -1 * translation.x;

        [self layoutSubviewsToWidth:0];
        __weak typeof(self) weakSelf = self;
        [UIView animateWithDuration:MCPanelViewAnimationDuration delay:0 options:0 animations:^{
            typeof(self) strongSelf = weakSelf;
            [strongSelf layoutSubviewsToWidth:width];
        } completion:^(BOOL finished) {
        }];

        CGFloat offset = self.maxWidth - width;
        if (direction == MCPanelAnimationDirectionLeft) {
            offset *= -1;
        }
        [pan setTranslation:CGPointMake(offset, translation.y) inView:pan.view];
    }

    if (!self.parentViewController) {
        return;
    }

    CGFloat newWidth = [pan translationInView:pan.view].x;
    if (self.direction == MCPanelAnimationDirectionRight) {
        newWidth *= -1;
    }
    newWidth += self.maxWidth;
    CGFloat ratio = newWidth / self.maxWidth;

    switch (pan.state) {
        case UIGestureRecognizerStateBegan:
        case UIGestureRecognizerStateChanged: {
            [self layoutSubviewsToWidth:newWidth];
            break;
        }

        case UIGestureRecognizerStateEnded:
        case UIGestureRecognizerStateCancelled: {
            CGFloat threshold = MCPanelViewGestureThreshold;

            // invert threshold if we started a screen edge pan gesture
            if ([pan isKindOfClass:[UIScreenEdgePanGestureRecognizer class]]) {
                threshold = 1 - threshold;
            }

            if (ratio < threshold) {
                [self dismiss];
            }
            else {
                __weak typeof(self) weakSelf = self;
                [UIView animateWithDuration:MCPanelViewAnimationDuration delay:0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
                    typeof(self) strongSelf = weakSelf;
                    [strongSelf layoutSubviewsToWidth:strongSelf.maxWidth];
                } completion:^(BOOL finished) {
                }];
            }
            break;
        }
        default:
            break;
    }
}

1 个答案:

答案 0 :(得分:0)

这是图书馆的known issue

引用matthewcheok:

  

延迟主要是由于面板捕获背景图像以提前应用图像模糊。当触摸手势或以编程方式打开手势,然后使用UIView内容模式裁剪图像时,它只执行一次,仅显示面板遮挡的相关部分。