2012-12-18 39 views
1

我現在已經陷入了這個問題超過2周!在我的項目中,我有1個單獨的ViewController(幻燈片)我想要啓用橫向和縱向。剩下的所有控制器/視圖(幻燈片)我只想啓用縱向模式。在Modal segue(ViewController)中顯示UINavigationController?

棘手的部分是,我所指的「ViewController」連接到NavigationControllers和TabBarControllers。請參閱下面的方案,其中我要啓用橫向/縱向的ViewController命名爲:ReferredViewController。

TabBarController ----> NavigationController ----> FristViewController - (推送事件) - > ReferredViewController

到目前爲止,我已經嘗試做一個類別對於NavigationControllers和TabBarControllers。但是由於我的NavigationControllers和TabBarControllers被放置在項目的最開始,所以會爲整個項目設置規則。我的ReferredViewController放置在項目「storyboard」的末尾或中間。我試圖通過代碼設置規則,以及單個ReferredViewController沒有任何成功。

我最好的辦法是將FirstViewController和ReferredViewController之間的事件從「push」改變爲「modal」。然後,ReferredViewController可以旋轉縱向/橫向,項目的其餘部分被鎖定在縱向。但是,正如您所知道的,所有導航(導航欄)都將丟失,並且用戶將陷入這張幻燈片中。

所以我試圖用在ReferredViewController.m文件下面的代碼示例,使導航欄:

ShowTaskViewController *detailViewController = [[ShowTaskViewController alloc] init]; 
UINavigationController *navController = [[UINavigationController alloc]  initWithRootViewController:detailViewController]; 

navController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; 
[self.navigationController presentModalViewController:navController animated:YES completion:nil]; 
[navController release]; 
[detailViewController release]; 

但OFC什麼也沒有發生,我再次返回到原​​點:O型。臥槽!

回答

0

你必須騎UITaBarController,因爲它是你的基礎視圖控制器。我已經爲我的導航控制器做了這個。告訴我這是否有幫助。

@interface UINavigationController (Autorotation) 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation; 
- (BOOL) shouldAutorotate; 
- (NSUInteger) supportedInterfaceOrientations; 
@end 

@implementation UINavigationController (Autorotation) 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{ 

if ([self.visibleViewController isKindOfClass:[MWPhotoBrowser class]] || [self.visibleViewController isKindOfClass:[ZoomPictureViewController class]]) { 
    return YES; 
} 
return (toInterfaceOrientation == UIInterfaceOrientationPortrait); 
} 

-(BOOL) shouldAutorotate{ 
    return YES; 
} 

-(NSUInteger) supportedInterfaceOrientations{ 

    if ([self.visibleViewController isKindOfClass:[MWPhotoBrowser class]] ||  [self.visibleViewController isKindOfClass:[ZoomPictureViewController class]]) { 
    return UIInterfaceOrientationMaskAll; 
} 

return UIInterfaceOrientationMaskPortrait; 
} 
1

在這一行:

[self.navigationController presentModalViewController:navController 
              animated:YES 
              completion:nil]; 

你混爲一談2種UIViewController的實例方法:

- (void)presentViewController:(UIViewController *)viewControllerToPresent 
        animated:(BOOL)flag 
        completion:(void (^)(void))completion 

- (void)presentModalViewController:(UIViewController *)modalViewController 
          animated:(BOOL)animated 

其中第一個是現在的標準,第二種方法在iOS6的被棄用。

此外,呈現視圖控制器應該是self(ReferredViewController),而不是self的navigationController。

您呈現視圖控制器因此解僱自己

[[self presentingViewController] dismissViewControllerAnimated:YES 
                completion:(void (^)(void))completion]; 

但是看看fibnochi的答案,也可能是爲你實現你的結果更好的辦法。

相關問題