2012-06-21 54 views
4

我已經成功地創建了一個圖標菜單,顯示從tabBar選擇。您可以以縱向或橫向查看此菜單。動畫UIViews獲得交叉淡入淡出效果不太好

因爲屏幕上的空間我已經使它在肖像中,你可以查看4x4圖標..但是由於在風景中查看時的尺寸,這種劑量不能很好地工作..所以我已經做到了讓你可以查看2行6和1行4.因此,我決定爲菜單創建兩個UIViews,當設備旋轉時,我在兩個視圖之間切換。

即如果肖像當前和設備是旋轉負載景觀和卸載肖像,反之亦然。

這是我使用的改變對設備旋轉視圖的代碼,這個工作完全正常(也許不是最好的代碼,但它的我能做的最好的)

if ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationPortrait) 
     { 
      if([jumpBarContainerLandscape superview]) 
      { 
      // Device is changing from landscape to protrait change views to fit 
      // load landscape view 
      jumpBarContainerPortrait = [[UIView alloc] initWithFrame:CGRectMake(0.0, (367 - jumpBarHeightPortrait), 320.0, (jumpBarHeightPortrait + 49.0))]; 
      jumpBarContainerPortrait.backgroundColor = [UIColor scrollViewTexturedBackgroundColor]; 
      jumpBarContainerPortrait.alpha = 0.0; 

      // add jumpbar container to view 
      [self.view insertSubview:jumpBarContainerPortrait belowSubview:actionTabBar]; 

      [UIView animateWithDuration:0.2 
            delay:0.0f 
           options:UIViewAnimationCurveEaseIn 
          animations:^{ 

           jumpBarContainerLandscape.alpha = 0.0; 


          } completion:^(BOOL finished) { 
           if (finished) { 


           } 
          }]; 


      [UIView animateWithDuration:0.2 
            delay:0.0f 
           options:UIViewAnimationCurveEaseIn 
          animations:^{ 

           jumpBarContainerPortrait.alpha = 1.0; 


          } completion:^(BOOL finished) { 
           if (finished) { 

            // remove subView for superView 
            [jumpBarContainerLandscape removeFromSuperview]; 
           } 
          }]; 

      } 
     } 
     else if ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeLeft || [[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeRight) 
     { 
      if ([jumpBarContainerPortrait superview]) 
      { 
      // Device is changing from portrait to landscape change views to fit 
      // load landscape view 
      jumpBarContainerLandscape = [[UIView alloc] initWithFrame:CGRectMake(0.0, (207 - jumpBarHeightLandscape), 480.0, (jumpBarHeightLandscape + 49.0))]; 
      jumpBarContainerLandscape.backgroundColor = [UIColor scrollViewTexturedBackgroundColor]; 
      jumpBarContainerLandscape.alpha = 0.0; 

      // add jumpbar container to view 
      [self.view insertSubview:jumpBarContainerLandscape belowSubview:actionTabBar]; 


       // fade out 
      [UIView animateWithDuration:0.2 
            delay:0.0f 
           options:UIViewAnimationCurveEaseIn 
          animations:^{ 

           jumpBarContainerPortrait.alpha = 0.0; 


          } completion:^(BOOL finished) { 
           if (finished) { 


           } 
          }]; 

       // fade in 
      [UIView animateWithDuration:0.2 
            delay:0.0f 
           options:UIViewAnimationCurveEaseIn 
          animations:^{ 


           jumpBarContainerLandscape.alpha = 1.0; 


          } completion:^(BOOL finished) { 
           if (finished) { 

            // remove subView for superView 
            [jumpBarContainerPortrait removeFromSuperview]; 
           } 
          }]; 
      } 
     } 

現在的問題我有兩個UIViews之間的動畫是相當醜陋的,它不是很流暢,你可以看到兩個不同的意見,在動畫等,這是不受歡迎的。我想知道如果有人可以想出一個很好的方法來交叉淡入兩個製作它看起來稍微平滑等...

任何幫助將不勝感激。

編輯:

所以我試着建立一個CATransaction,但是我有一個線上的錯誤給我這個錯誤爲「UIView的」無可見@interface聲明選擇「jumpBarContainerPortrait」我已經加入到我得到這個錯誤低於..任何幫助將不勝感激

[CATransaction begin]; 
      CATransition *animation = [CATransition animation]; 
      animation.type = kCATransitionFade; 
      animation.duration = 3.50; 

      [self.view insertSubview:jumpBarContainerPortrait belowSubview:actionTabBar]; 

      [[self.view jumpBarContainerPortrait] addAnimation:animation forKey:@"Fade"]; // Error is happening here! 
      [CATransaction commit]; 
+0

您是否嘗試過使用'CATransition'而不是'kCATransitionFade'類型。 – sooper

回答

7

而不是你的獨立淡入和淡出的動畫該行的註釋,使用的UIView方法「transitionFromView」。以下是一個示例:

 [UIView transitionFromView:jumpBarContainerLandscape 
          toView:jumpBarContainerPortrait 
          duration:crossDissolveTime 
          options:UIViewAnimationOptionTransitionCrossDissolve 
         completion:NULL]; 
+0

很酷的感謝,這是一種工作..它與標籤欄做奇怪的事情,即使我在我的tabBar後面插入jumpBarContainerPortrait在轉換髮生後,標籤欄上出現視圖...所以只是想弄清楚現在出來。 – HurkNburkS

+1

太好了。如果它幫助你,請「接受」我的答案。 –

+0

是的事實證明,它給我的動畫有稍差的結果..我不知道爲什麼,但它會淡出我的標籤欄以及...這是很奇怪的,它是一個很好的解決方案,但它沒有爲我的動畫做任何事情,所以我將保持這個線程打開,看看是否有其他人有建議..如果不是,那麼我想我會把你的標記爲正確的。 – HurkNburkS