2014-01-22 3 views
0

왼쪽 컨트롤러와 오른쪽 컨트롤러를 드로잉하기 위해 iOS 앱에서 MCPanelViewController을 사용했습니다 (안드로이드는 컨트롤 드로어가 내장되어 있음). 그것은 훌륭하게 작동하지만 약간 늦은 제스처와 함께 오지는 않습니다. 누군가가 문제에 대한 답을 얻은다면 좋을 것입니다.드로어가 거의 사용하지 않습니다. MCPanelViewController를 사용합니다.

- (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입니다 :

UIViewController (MCPanelViewControllerInternal) 카테고리에서 코드입니다.

지연이 패널이 사전에 이미지 블러를 적용 할 수있는 배경 이미지를 캡처 주로 방법에 있습니다 :

는 matthewcheok을 인용합니다. 이 작업은 제스처가 트리거되거나 프로그래밍 방식으로 열렸을 때 한 번만 수행 한 다음 UIView 내용 모드를 사용하여 이미지를 잘라내어 패널에서 가려져있는 관련 부분 만 표시합니다.