2016-09-14 40 views
0

Hi我的TabBarViewController層次結構就像這樣。與tabbar連接的所有ViewControllers都沒有navigationControllerSingle UIViewController UITabBar內部自動旋轉

UIViewController(主視圖),當推其導航到基於ViewControllertabBar在索引0,用戶可以在導航欄上使用後退按鈕在任何時間來自tabBarViewControllers回到家裏viewController

UITabBarViewController (BaseViewController) 
    -ViewController0,(NO Navigation ViewController) 
    -ViewController1 (NO Navigation ViewController) 
    -ViewController2 (NO Navigation ViewController) 
    -ViewController3 (NO Navigation ViewController) 
    -ViewController4 (NO Navigation ViewController) 

我用的基於ViewControllerTabbar這種做法,因爲Tabbar不在家ViewController

我想在縱向和橫向上僅自動旋轉ViewController2。我的項目只能使用肖像模式。

我嘗試了很多東西,如THIS,但它沒有得到。

+0

聽起來不清楚,你能詳細說明一下嗎? –

+0

@ Mr.UB我更新了詳細信息 – ChenSmile

+0

檢查此:http://stackoverflow.com/questions/39159444/how-to-get-navigation-based-template-functionality-in-swift-programming/39159793#39159793,讓我知道你明白了什麼。 –

回答

1

嗨經過很多研究我發現,無論是TabbarUIVicontroller

根據我的問題,我的項目是在肖像模式,我只想要單一視圖控制器自動旋轉。下面是幫助我的步驟。

1 - 在應用Delegate.h

@property (assign, nonatomic) BOOL shouldRotate; 

2 - 在應用Delegate.m

- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(nullable UIWindow *)window NS_AVAILABLE_IOS(6_0) __TVOS_PROHIBITED 
{ 
_shouldRotate = [[NSUserDefaults standardUserDefaults]boolForKey:@"rotateKey"]; 
NSLog(@"Did I get to InterfaceOrientation \n And the Bool is %d",_shouldRotate); 

if (self.shouldRotate == YES){ 
    return UIInterfaceOrientationMaskAll; 
}else{ 
    return UIInterfaceOrientationMaskPortrait; 
}  
} 

3 - 現在哪家的UIViewController,你想自動旋轉

-(void)viewDidAppear:(BOOL)animated 
{ 
    [super viewDidAppear:YES];  
    BOOL rotate = YES; 
[[NSUserDefaults standardUserDefaults]setBool:rotate forKey:@"rotateKey"]; 
[[NSUserDefaults standardUserDefaults]synchronize];  
} 

-(BOOL)shouldAutorotate 
{ 
return YES; 
} 

4 -Trick部分是

如果你做的所有上述步驟,您的視圖控制器將獲得自動旋轉,如果u來自當前視圖控制器,它是橫向模式回來。先前的視圖控制器將在橫向上自動旋轉並保持連鎖。

所以,爲了避免這種情況,

如果從視圖控制器A到視圖控制器B.視圖控制器自動旋轉,然後在視圖控制器A-

5 - 使用此代碼。 -

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

BOOL rotate = NO; 
[[NSUserDefaults standardUserDefaults]setBool:rotate forKey:@"rotateKey"]; 
[[NSUserDefaults standardUserDefaults]synchronize]; 
} 
-(BOOL)shouldAutorotate 
{  
return NO; 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)toInterfaceOrientation 
{ 
    return (toInterfaceOrientation == UIInterfaceOrientationPortrait); 
} 

#if __IPHONE_OS_VERSION_MAX_ALLOWED < 90000 
- (NSUInteger)supportedInterfaceOrientations 
#else 
- (UIInterfaceOrientationMask)supportedInterfaceOrientations 
#endif 
{ 
dispatch_async(dispatch_get_main_queue(), ^{ 
    // UI Updates 

}); 
    return UIInterfaceOrientationMaskPortrait; 
} 
+0

AsSalamu Alaikum Imran之間有Home View控制器,無法幫助解決視頻通話問題。我找到了一個名爲[oovoo SDK]的API(https://developers.oovoo.com)。希望你在其他一些任務中。如果您想在您的應用中使用視頻通話功能,請使用此SDK。這很容易實現。謝謝。 – NAZIK

+0

@NAZIK w/a好的兄弟.. – ChenSmile