2014-01-22 24 views
0

我在用於繪製左右控制器的iOS應用程序中使用MCPanelViewController(因爲android內置控制抽屜)。它運作良好,但它並沒有帶來遲到的姿態。如果任何人有問題的答案,那就太好了。使用MCPanelViewController的抽屜來得晚了

這是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; 
    } 
} 
+0

你是什麼意思,「它不帶手勢來得晚點」?你的意思是手勢比平常晚得多嗎?你可以發佈你的代碼到目前爲止? – Malloc

+0

是的,你是正確的姿態被認可有點晚,可能是太 –

回答

0

這是庫的known issue

引述matthewcheok:

延遲的主要原因是路面板捕獲的背景圖像應用圖像模糊提前。它只會執行一次,當手勢被觸發或以編程方式打開時,然後使用UIView內容模式裁剪圖像以僅顯示面板遮擋的相關部分。