2011-07-29 22 views
6

這個問題已經被問了很多例如here,但據我所知,尚未完全回答。UIModalTransitionStylePartialCurl用的UITabBarController

我有一個UITabBarControllerUINavigationController作爲其中一個選項卡的根vc,其本身有一個MKMapView作爲其根vc。我想要的地圖部分地向上捲曲,,同時保留標籤欄(類似於地圖應用程序)。

到目前爲止,所有我設法得到工作是整個視圖捲曲,這是不一樣漂亮。

我見過的解決方案是將hidesBottomBarWhenPushed屬性設置爲NO,這將有意義,但這似乎不起作用,(除非我做錯了什麼)。

爲了清楚起見,我的代碼如下:

MyVC *aView = [MyVC init]; 
aView.modalTransitionStyle = UIModalTransitionStylePartialCurl; 
aView.hidesBottomBarWhenPushed = NO; 

對於露部分,我曾嘗試下面的兩個備選方案,這兩者都不似乎工作:

[self presentModalViewController:updateStatus animated:YES]; 
[[self navigationController] presentModalViewController:updateStatus animated:YES]; 

任何幫助非常讚賞。

+0

FYI以上init方法僅僅是一個靜態的便捷方法,它確實分配等 – danhopwood

回答

4

我已經沖刷的StackOverflow(和互聯網)的解決這個問題。這個問題已被多次提出,但正如你所指出的那樣,從來沒有得到充分的回答。如果不重要的話,許多solutions都給出了可接受的解決方案,例如下部工具欄是否捲起。

Others提供了一個解決方案,使用UIView動畫/ CoreAnimation而不是UIModalTransitionStylePartialCurl作爲模式轉換樣式;這最壞的情況是App Store中不允許的解決方案,最多與UIModalTransitionStylePartialCurl(例如,捲曲的形狀不同)獲得的效果不盡相同。

這些解決方案都沒有提供模擬蘋果在地圖應用程序中的解決方案(即使用UIModalTransitionStylePartialCurl,但在屏幕底部留下不捲曲的UIToolbar)的答案。

我會繼續在這個傳統不完整的答案,因爲你問一個UITabBarController和我的解決方案沒有具體解決這種情況。但是,它確實解決了我的問題,即用底部的未捲曲工具欄捲起半頁捲曲。

必須有一個更優雅的方式來做到這一點,但我這是怎麼管理的。

我的AppDelegaterootViewControllerUIViewController的一個子類,我將其稱爲TAContainerViewControllerTAContainerViewController管理一個)屏幕(以下簡稱「東東捲曲」),TAContentViewController和實際內容B)的內容「後面」 TAContentViewController(例如設置),我會打電話給TAUnderCurlViewController

我的TAContainerViewController的實例的屬性爲TAContentViewControllerTAUnderCurlViewController。這是我內容的UIViewTAContentViewControllerview屬性的子視圖;同樣地,用戶在捲曲下看到的是TAUnderCurlViewControllerview特性。

TAContainerViewControllerinit方法我一定要做到以下幾點:

_underCurlVC.modalTransitionStyle = UIModalTransitionStylePartialCurl; 

而捲曲的內容頁面下透露,我設置調用此代碼的作用:

[self.contentVC presentModalViewController:self.underCurlVC animated:YES];` 

其中selfTAContainerViewControllercontentVCTAContentViewController一個實例,underCurlVCTAUnderCurlViewController一個實例。

要解散視圖,只需[self.contentVC dismissModalViewControllerAnimated:YES];

當模態視圖關閉時,contentVC的框架似乎會出現一些奇怪的現象,所以我在模態視圖關閉時手動重置框架。

我已經發布了一個樣例項目,其詳細信息在Github。希望有人可以把它變成一個稍微更優雅的解決方案,或者擴展它以使用UINavigationControllerUITabBarController。我認爲訣竅是將視圖控制器從Cocoa子類中明確定義的關係中拉出來,所以也許子類化這些專業的視圖控制器就可以做到這一點。

1

蒂姆阿諾德的反應對我很好,謝謝!

一個陷阱要提防:您的模態頁面捲曲的過渡將接管整個屏幕,如果你的內容視圖控制器添加爲容器視圖控制器的孩子。您可以不添加它作爲孩子,但然後沒有任何視圖生命週期方法將被調用您的內容控制器(例如viewDidLoad,viewWillAppear),這可能是一個問題。

幸運的是,有一種解決方法。在容器中的控制器:

  • 添加內容控制器作爲一個孩子在viewDidLoad
  • viewDidAppear
  • viewWillDisappear它重新添加爲孩子取下它作爲一個孩子。

這樣,你的內容控制器得到它的生命週期方法調用,同時仍然能夠做到不佔用整個屏幕模態頁面捲曲的過渡。

這裏是一個最基本的解決方案的整個代碼:

@interface XXContainerController : UIViewController 
@property (strong, nonatomic) UIViewController *contentController; 
@property (nonatomic) BOOL curled; 
@end 

@implementation XXContainerController 

@synthesize contentController = _contentController; 
@synthesize curled = _curled; 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    self.contentController = [self.storyboard 
     instantiateViewControllerWithIdentifier:@"SomeControllerInStoryboard"]; 

    // Add content controller as child view controller. 
    // This way, it will receive all the view lifecycle events 
    [self addChildViewController:self.contentController]; 
    self.contentController.view.frame = self.view.bounds; 
    [self.view addSubview:self.contentController.view]; 
    [self.contentController didMoveToParentViewController:self];  
} 

- (void)viewDidAppear:(BOOL)animated 
{ 
    [super viewDidAppear:animated]; 

    // Remove the content controller as child view controller. 
    // This way, the modal page curl transition will 
    // not take over the whole screen. 
    // NOTE: need to wait until content controller has appeared 
    // (which will happen later). 
    // Achieve this by running the code at the end of the animation loop 
    [UIView animateWithDuration:0 animations:nil completion:^(BOOL finished) { 
     [self.contentController removeFromParentViewController]; 
    }]; 
} 

- (void)viewWillDisappear:(BOOL)animated 
{ 
    [super viewWillDisappear:animated]; 

    // Add the content controller as child view controller again 
    // so it receives the view lifecycle events 
    [self addChildViewController:self.contentController]; 
} 

- (void)setCurled:(BOOL)curled 
{ 
    if (curled == _curled) return; 

    _curled = curled; 

    // Curl up the content view and show underneath controller's view 
    if (curled) { 
     // Note you can specify any modal transition in storyboard 
     // E.g. page curl, flip horizontal 
     [self.contentController 
      performSegueWithIdentifier:@"SomeModalSegueDefinedInStoryboard" 
      sender:self]; 

    // Uncurl and show the content controller's view again 
    } else { 
     [self.contentController dismissModalViewControllerAnimated:YES]; 

     // Have to do this, otherwise the content controller's view 
     // gets messed up for some reason 
     self.contentController.view.frame = self.view.bounds; 
    } 
} 

@end 
+0

感謝闡述!我的解決方案的一個不完整的方面是它不使用適當的View Controller Containment API。 –

相關問題