2013-09-30 93 views
2

我正在將iOS 7中引入的新自定義視圖控制器轉換與UINavigationController結合使用。我在UINavigationControllerDelegate實施在自定義視圖控制器轉換中抑制導航推動動畫

-navigationController:animationControllerForOperation:fromViewController:toViewController: 

,實現UIViewControllerAnimatedTransitioning協議和自定義的過渡精美的作品。

但是我想在推視圖控制器時阻止導航欄中的移動動畫。有趣的是,流行動畫很好,導航項目只是淡化而不是移位。但推動動畫從右側移動導航項目。

我找到了部分解決方案,將-pushViewController:animated:替換爲-setViewControllers:animated:,並將新視圖控制器添加到viewControllers陣列中。這會執行正確的阿爾法衰落動畫 - 除了第一次將視圖控制器壓入堆棧。隨後的彈出/推送很好。

任何想法如何實現這種效果? Calendar.app和Photos.app也實現了這一點,所以它應該是可能的(儘管它可能是使用集合視圖時的特定行爲)。

+0

我不知道,如果你還在這裏有一個問題,但我無法重現它。你能提供更多細節嗎?當我使用'animationControllerForOperation'指定一個自定義轉換時,動畫以我期望的方式影響我的內容,並且導航欄淡出(對於push和pop)。 – Rob

+0

它會褪色,但它也會做移位動畫。我會發布我的解決方法。 –

回答

0

我寫了一個解決辦法,從導航欄子視圖刪除所有位置的動畫:

@implementation UIView (FTNavigationBar) 

static CGFloat leftMargin = 8; 

- (void)removePushAnimation { 
    CAAnimation *animation = [self.layer animationForKey:@"position"]; 
    if (animation) { 
     if ([animation isKindOfClass:CABasicAnimation.class] && ((CABasicAnimation*)animation).fromValue) { 
      CGPoint point = [((CABasicAnimation*)animation).fromValue CGPointValue]; 
      CGFloat halfSuperWidth = [self superviewOfKind:FTNavigationBar.class].bounds.size.width/2; 
      if ((fabs(point.x - halfSuperWidth) < 2 && fabs(self.center.x - halfSuperWidth) > 2) || fabs(point.x - self.frame.size.width/2 - leftMargin) < 2) { 
       self.layer.position = point; 
      } 
     } 
     [self.layer removeAnimationForKey:@"position"]; 
    } 
    for (UIView *subview in [self subviews]) { 
     [subview removePushAnimation]; 
    } 
} 

@end 
相關問題