0

的選項卡時,只能旋轉的一些看法這裏是我無法弄清楚如何工作的流程。 (當我聲明(工作)時,這意味着在當前狀態下,該視圖的方向規則正常工作)我如何與一個UINavigationController工作作爲一個的UITabBarController

第一次查看:UITabBarController的選項卡的UINavigationController的堆棧上的TableView。

TableView只允許爲肖像。 (working) 當您將TableView旋轉到橫向模式時,會出現一個類似於coverflow的自定義UIView(我將在稍後解釋該問題)。

甲選擇上的tableview由上推到堆棧一個UIScrollView。

UIScrollView的是允許所有方向。 (工作)

當UIScrollView的是在橫向模式和用戶打回他們被帶到了自定義的UIView是喜歡的CoverFlow和只允許景觀。

問題在這裏。由於UIScrollView允許完整旋轉,因此它允許TableView旋轉以及橫向旋轉。

我有一個方法附加到通知「UIDeviceOrientationDidChangeNotification」,檢查自定義視圖是否是當前控制器,如果是,並且用戶已經旋轉回肖像我需要彈出自定義視圖並顯示錶視圖。

表視圖有轉回肖像,這確實是好的,只要用戶不會看到它。當我創建自定義動畫時,除了一些奇怪的看不見的黑盒子,它似乎隨着設備旋轉之前,我淡出自定義視圖到桌面視圖非常好。

此外,爲了確保我的tableview將旋轉到縱向,我必須允許customview支持所有方向,因爲系統查看當前視圖(在我的代碼中)是否允許該應用旋轉到一定的方向。正因爲如此,我提出的許多解決方案將在桌面視圖重新聚焦時顯示自定義視圖旋轉到縱向。

我的其他問題非常相似。如果您正在查看tableview並旋轉customview的模態視圖。在此視圖上進行選擇時,它會將UIScrollview推入堆棧,但由於Tableview僅支持縱向,所以在設備處於橫向模式時,UIScrollview以縱向顯示。

我該如何克服這些可怕的塊?

這是我目前的嘗試:

當談到與工作的UITabBarController系統真的只關心什麼tabbarcontroller不得不說的旋轉。

目前無論何時報告一個視圖加載它支持的方向。

TabBarController.m

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
switch (self.supportedOrientation) { 
    case SupportPortraitOrientation: 
     [[UIApplication sharedApplication] setStatusBarHidden:NO animated:YES]; 
     return (interfaceOrientation == UIInterfaceOrientationPortrait); 
     break; 
    case SupportPortraitUpsideDownOrientation: 
     [[UIApplication sharedApplication] setStatusBarHidden:NO animated:YES]; 
     return (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown); 
     break; 
    case SupportPortraitAllOrientation: 
     [[UIApplication sharedApplication] setStatusBarHidden:NO animated:YES]; 
     return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown); 
     break; 
    case SupportLandscapeLeftOrientation: 
     [[UIApplication sharedApplication] setStatusBarHidden:YES animated:YES]; 
     return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft); 
     break; 
    case SupportLandscapeRightOrienation: 
     [[UIApplication sharedApplication] setStatusBarHidden:YES animated:YES];    
     return (interfaceOrientation == UIInterfaceOrientationLandscapeRight); 
     break; 
    case SupportLandscapeAllOrientation: 
     [[UIApplication sharedApplication] setStatusBarHidden:YES animated:YES]; 
     return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight); 
     break; 
    case SupportAllOrientation: 
     if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) { 
      [[UIApplication sharedApplication] setStatusBarHidden:YES animated:YES]; 
     }else { 
      //[[UIApplication sharedApplication] setStatusBarHidden:NO animated:YES]; 
     } 
     return YES; 
     break; 
    default: 
     return (interfaceOrientation == UIInterfaceOrientationPortrait); 
     break; 
    } 

}

的代碼塊是我的UINavigationController的一部分,並且是在響應該通知UIDeviceOrientationDidChangeNotification的方法。它負責彈出customview並顯示tableview。有兩種不同的版本,最初是針對兩種不同版本的SDK,但兩者都非常接近解決方案。

第一個在3.0上不支持的原因是由於某些原因,您無法將視圖顯示並顯示爲模式視圖。不知道這是一個錯誤還是一個功能。

第二種解決方案工作得非常好,除了我看到一個圍繞iphone旋轉的外框。

if ([[self topViewController] isKindOfClass:FlowViewController.class]) { 
    NSString *iphoneVersion = [[UIDevice currentDevice] systemVersion]; 
    double version = [iphoneVersion doubleValue]; 
    if(version > 3.0){ //1st solution 
     //if the delivered app is not built with the 3.1 SDK I don't think this will happen anyway 
     //we need to test this 
     [self presentModalViewController:self.flowViewController animated:NO]; 
     //[self toInterfaceOrientation:UIDeviceOrientationPortrait animated:NO]; 
     [self popViewControllerAnimated:NO]; 
     [self setNavigationBarHidden:NO animated:NO]; 
     [self dismissModalViewControllerAnimated:YES]; 
    }else{ //2nd solution 
     DLog(@"3.0!!"); 
     //[self toInterfaceOrientation:UIDeviceOrientationPortrait animated:NO]; 
     CATransition *transition = [CATransition animation]; 
     transition.duration = 0.50; 
     transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; 
     transition.type = kCATransitionPush; 
     transition.subtype = kCATransitionFade; 

     CATransition *tabBarControllerLayer = [CATransition animation]; 
     tabBarControllerLayer.duration = 0.50; 
     tabBarControllerLayer.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; 
     tabBarControllerLayer.type = kCATransitionPush; 
     tabBarControllerLayer.subtype = kCATransitionFade; 

     [self.tabBarController.view.layer addAnimation:transition forKey:kCATransition]; 
     [self.view.layer addAnimation:transition forKey:kCATransition]; 
     [self popViewControllerAnimated:NO]; 
     [self setNavigationBarHidden:NO animated:NO]; 

    } 
    [self performSelector:@selector(resetFlow) withObject:nil afterDelay:0.75]; 

} 

我接近確信沒有解決方案,除了手動旋轉,這弄亂了鍵盤旋轉。

任何意見將不勝感激!

謝謝。

回答

0

如果你有一個導航控制器在標籤欄控制器,你只想讓一些視圖旋轉我有解決方案。它可能不適合每個人,它可能不是最乾淨的代碼,但到目前爲止,它是唯一的解決方案。

此外,此方法假定您不想在第一個視圖中看到標籤欄,儘管您可以使用popOverControllers實現我的解決方案,但我不確定。

創建的TabBar控制器 創建導航控制器 創建第二個導航控制器,將不會的TabBar控制器 上投放的TabBar控制器 配置方法,將pushViewController首先第一導航控制器:

起飛當前屏幕的屏幕截圖。 將該屏幕截圖放入UIViewController 推送UIViewController到第二個導航控制器 目前的第二個導航控制器模態 延遲約0.15秒後推動所需的視圖控制器到第二個導航控制器的導航堆棧。

現在您的當前控制器已關閉tabBarcontroller並且它的旋轉(因爲此導航控制器是以模態方式呈現的)獨立於tabBarController!

你必須做一些工作才能回到你的第一視圖,但這並不難。

這是一個詳細的解決方案,我會嘗試一段時間獲取代碼。他們更多的是這個答案,但這應該足以讓你開始,如果你需要幫助,讓我知道。

0

嗨,你可以嘗試這一切:

我使用的每一個針對這一行,所以你可以在任意視圖改變首選方向:

- (BOOL)shouldAutorotate 
{ 
    return YES; 
} 

- (NSUInteger)supportedInterfaceOrientations 
{ 
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { 
     return UIInterfaceOrientationMaskPortrait; 
    } else { 
     return UIInterfaceOrientationMaskAll; 
    } 
} 

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation 
{ 
    return UIInterfaceOrientationPortrait; 
} 

然後,你必須繼承的UINavigationController和的UITabBarController ,所以這裏是代碼:

//cCustomNavigationController.h file 

#import <UIKit/UIKit.h> 

@interface cCustomNavigationController : UINavigationController <UINavigationControllerDelegate> 

@end 

//cCustomNavigationController.m file 

#import "cCustomNavigationController.h" 

@interface cCustomNavigationController() 

@end 

@implementation cCustomNavigationController 

- (BOOL)shouldAutorotate { 
    return [self.visibleViewController shouldAutorotate]; 
} 

- (NSUInteger)supportedInterfaceOrientations { 
    return [self.visibleViewController supportedInterfaceOrientations]; 
} 

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { 
    return [self.visibleViewController preferredInterfaceOrientationForPresentation]; 
} 

@end 

//cCustomTabController.h file 

#import <UIKit/UIKit.h> 

@interface cCustomTabController : UITabBarController <UITabBarControllerDelegate> 

@end 

//cCustomTabController.m file 

#import "cCustomTabController.h" 

@interface cCustomTabController () 

@end 

@implementation cCustomTabController 

- (BOOL)shouldAutorotate { 
    return [self.selectedViewController shouldAutorotate]; 
} 

- (NSUInteger)supportedInterfaceOrientations { 
    return [self.selectedViewController supportedInterfaceOrientations]; 
} 

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { 
    return [self.selectedViewController preferredInterfaceOrientationForPresentation]; 
} 

@end 

現在你只需要使用這個類在任何你需要它,即創建您TabBarControler或您的NavigationController

//For the UINavigationController 
UINavigationController *navigationController = [[cCustomNavigationController alloc] init]; 

//For the UITabBarController 
UITabBarController *tabController = [[cCustomTabController alloc] init]; 

現在,您可以以您想要的方式控制所有視圖的旋轉,我正在使用它,它工作正常。

我希望這可以幫助你,但我不確定這是否是你需要的。

快樂編碼。

相關問題