2014-07-17 108 views
3

我試圖在iPad上實現一些自定義轉換,但我遇到了一些問題。由於X,Y座標不總是在transitionContextcontainerView左上角開始時設備旋轉我寫了下面的方法iOS 7自定義轉換問題

- (CGRect)rectForPresentedStateStart:(id<UIViewControllerContextTransitioning>)transitionContext 
{ 
    UIViewController *fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey]; 
    UIView *containerView = [transitionContext containerView]; 

    switch (fromViewController.interfaceOrientation) 
    { 
     case UIInterfaceOrientationLandscapeRight: 
      return CGRectMake(0, containerView.bounds.size.height, 
           containerView.bounds.size.width, containerView.bounds.size.height * 2/3); 
     case UIInterfaceOrientationLandscapeLeft: 
      return CGRectMake(0, - containerView.bounds.size.height * 2/3, 
           containerView.bounds.size.height, containerView.bounds.size.height * 2/3); 
     case UIInterfaceOrientationPortraitUpsideDown: 
      return CGRectMake(- containerView.bounds.size.width * 2/3, 0, 
           containerView.bounds.size.width * 2/3, containerView.bounds.size.height); 
     case UIInterfaceOrientationPortrait: 
      return CGRectMake(containerView.bounds.size.width, 0, 
           containerView.bounds.size.width * 2/3, containerView.bounds.size.height); 
     default: 
      return CGRectZero; 
    } 

} 

- (CGRect)rectForPresentedStateEnd:(id<UIViewControllerContextTransitioning>)transitionContext 
{ 
    UIViewController *toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey]; 
    UIView *containerView = [transitionContext containerView]; 


    switch (toViewController.interfaceOrientation) 
    { 
     case UIInterfaceOrientationLandscapeRight: 
      return CGRectOffset([self rectForPresentedStateStart:transitionContext], 0, - containerView.bounds.size.height * 2/3); 
     case UIInterfaceOrientationLandscapeLeft: 
      return CGRectOffset([self rectForPresentedStateStart:transitionContext], 0, containerView.bounds.size.height * 2/3); 
     case UIInterfaceOrientationPortraitUpsideDown: 
      return CGRectOffset([self rectForPresentedStateStart:transitionContext], containerView.bounds.size.width * 2/3, 0); 
     case UIInterfaceOrientationPortrait: 
      return CGRectOffset([self rectForPresentedStateStart:transitionContext], - containerView.bounds.size.width * 2/3, 0); 
     default: 
      return CGRectZero; 
    } 
} 

在肖像模式和顛倒一切似乎很好地工作。問題在於景觀。

  1. 當器件取向是UIInterfaceOrientationLandscapeLeft的視圖中消失用於第二過渡開始之前。

  2. 當設備方向是UIInterfaceOrientationLandscapeRight我得到了以下問題:導航欄是很小,而且在過渡結束喜歡在照片

Issue with navigation bar when transition occurs

問題與導航變爲標準當發生轉變時

After transition is completed

過渡完成後

或我不知道如果這些蟲子從蘋果,如果我做錯了什麼,如果是我該如何解決這些問題?

+0

我希望這會幫助你http://stackoverflow.com/questions/17794037/interface-builder-what-are-the-uiviews-layout-ios-6-7-deltas-for – Spynet

+0

@Spynet我試着改變它在我的表格視圖,但不幸的是沒有任何變化 – alecnash

+0

它仍然看起來相同或一些額外的行爲...。 – Spynet

回答

3

這絕對是一個錯誤的蘋果使用寬度高度和高度寬度。用於呈現動畫我使用這樣的事情:

if (self.presenting) { 
     toViewController.view.frame = [self rectForPresentedStateStart:transitionContext]; 
     [transitionContext.containerView addSubview:toViewController.view]; 
     [UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{ 
      fromViewController.view.frame = [self rectForDismissedState:transitionContext]; 
      toViewController.view.frame = [self rectForPresentedStateEnd:transitionContext]; 
     } completion:^(BOOL finished) { 
      [transitionContext completeTransition:YES]; 
     }];  
} 

如果我添加animateWithDuration方法後視圖([transitionContext.containerView addSubview:toViewController.view]; )與所述導航控制器的問題是固定的。仍然無法弄清楚爲什麼。

0

我想你的containerViewUIWindow。所以它的界限是獨立的,所以containerView.bounds.size.height在縱向和橫向上都是一樣的。

如果我是正確的,你需要在景觀

+0

不完全。這不像UIWindow。旋轉時,軸不會停留在左上角。所以一切都應該相應調整。 – alecnash