2011-12-04 67 views
2

我正在iOS 5上開發我的第一款Apple產品。當我使用UITabBarController的而不是時,在多個場景中保持一致的UITabBar對象的最佳方法是什麼?這只是一個標準的UIViewController。我有一個標籤欄,就像我想在一個場景中一樣工作,我希望能夠將它複製到我的其他4個場景中。iOS 5在多個場景中保持一致的標籤欄

+3

只是出於興趣,爲什麼不使用的UITabBarController? – Till

+0

3個字。打架俱樂部。 –

+1

[此問題]可能的重複(http://stackoverflow.com/questions/7304388/how-to-create-physical-menu-button-like-the-one-in-android-menu-in-iphone/7430533 #7430533)。 – aopsfan

回答

0

假設你真的不想使用UITabViewController,然後讓你的應用程序委託維持基準您的全球UITabBar對象,當您從視圖切換到視圖時,您可以請求該實例並將其添加到視圖層次結構中。

1

使用UIAppearance API在所有UITabBar實例上設置視覺屬性。

id appearance = [UITabBar appearance]; 
[appearance setBackgroundImage:someImage]; 
[appearance setTintColor:someTintColor]; 
//... 

Here小號UIAppearance代理「可以在UITabBar設置的屬性的列表SA」:

0

這是非常簡單和容易做(我已經在多個應用程序中完成)。

  1. 創建一個基於視圖的應用程序。我們將這樣創建的單個VC稱爲「MainViewController」。
  2. 使用圖像,按鈕和MainViewController.xib中的內容創建頂部欄。將頂級UIView的背景顏色設置爲「清除顏色」。
  3. 向此xib添加其他內容。
  4. 創建視圖控制器和Xib的所有視圖,你需要 顯示(包括初始/第一視圖)。我們稱之爲MyViewController1 & MyViewController2。
  5. 讓MainViewController與MyViewController1具有「有」關係。含義MainViewController將具有MyViewController1類型的成員變量/屬性。
  6. 同上MyViewController2。
  7. 在MainViewController的「viewDidLoad」方法中實例化MyViewController1 & 2。
  8. 將它們添加爲MainViewController的子視圖。
  9. 將隱藏的屬性添加到NO爲初始視圖(MyViewController1也許)和YES爲另一個。
  10. 此時,您會看到MainViewController的頂部欄和MyViewController1的視圖。
  11. 當您需要切換到MyViewController2時,只需將其隱藏屬性設置爲NO,並將MyViewController1的隱藏屬性設置爲YES。
  12. 如果你想從MyViewController1過渡動畫來 MyViewController2的CABasicAnimation/CATransition添加到 CALayers到MyViewController1 & MyViewController2(而不是 MainViewController)。然後,您的頂欄(在 MainViewController上繪製)將保持堅如磐石的穩定性,並且會在其下切換/動畫。
  13. 但是,如果您希望頂欄消失,並且新頂欄與下一個視圖一起顯示,請將CATransition/CAAnimation等附加到MainViewController的CALayer。

隨時問任何問題。

0

你可以做的是使用視圖來包裝你想成爲動態的內容。然後,您可以將第一個可見視圖添加爲此視圖的子視圖。接下來,您需要爲視圖之間的轉換(當前視圖和您想要更改的視圖)之間的轉換設置動畫,以模擬更改視圖控制器。這是我用過的兩個視圖之間的代碼。我的「包裝」視圖被稱爲內容視圖。您需要將其與您已設置的標籤欄進行整合...

[ contentView addSubview:view2 ]; 
[ view1 removeFromSuperview ]; 

CATransition *animation = [ CATransition animation ]; 

[ animation setType:kCATransitionPush ]; 
[ animation setSubtype:kCATransitionFromRight ]; 
[ animation setDuration:0.5 ]; 
[ animation 
setTimingFunction:[ CAMediaTimingFunction 
        functionWithName:kCAMediaTimingFunctionEaseInEaseOut 
    ] 
]; 

[[ contentView layer ] 
addAnimation:animation 
forKey:@"currentTransition" 
]; 

試一下!

0

這不是標準的方式,但如果你真的想在你的應用程序中使用tabBar功能而不使用tabBar。

在每個視圖(尺寸爲199 X 49)的底部創建一個4-5個自定義按鈕(帶圖像),以便它完全消耗視圖的底部(如tabBar)。只有其中一個按鈕在一個視圖休息都是禁用的。你所提供的按鈕功能也應該改變圖像,以顯示當前標籤被點擊。

相關問題