Single UIViewController UITabBar内部自动旋转

问题描述:

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://*.com/questions/39159444/how-to-get-navigation-based-template-functionality-in-swift-programming/39159793#39159793,让我知道你明白了什么。 –

嗨经过很多研究我发现,无论是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