嗨經過很多研究我發現,無論是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://stackoverflow.com/questions/39159444/how-to-get-navigation-based-template-functionality-in-swift-programming/39159793#39159793,讓我知道你明白了什麼。 –