Single UIViewController UITabBar内部自动旋转
问题描述:
Hi我的TabBarViewController
层次结构就像这样。与tabbar
连接的所有ViewControllers
都没有navigationController
。Single UIViewController UITabBar内部自动旋转
UIViewController
(主视图),当推其导航到基于ViewController
tabBar
在索引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)
我用的基于ViewController
Tabbar
这种做法,因为Tabbar
不在家ViewController
。
我想在纵向和横向上仅自动旋转ViewController2
。我的项目只能使用肖像模式。
我尝试了很多东西,如THIS,但它没有得到。
答
嗨经过很多研究我发现,无论是Tabbar或UIVicontroller。
根据我的问题,我的项目是在肖像模式,我只想要单一视图控制器自动旋转。下面是帮助我的步骤。
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;
}
听起来不清楚,你能详细说明一下吗? –
@ Mr.UB我更新了详细信息 – ChenSmile
检查此:http://*.com/questions/39159444/how-to-get-navigation-based-template-functionality-in-swift-programming/39159793#39159793,让我知道你明白了什么。 –