![](/img/trans.png)
[英]How to setup a relationship between the presenting View Controller and the presented View Controller?
[英]Rotate presented view and lock the orientation of presenting view controller
我正在研究僅支持橫向定位的iPad應用程序,我想允許一些呈現的視圖控制器支持所有方向而不改變呈現視圖控制器的方向。 我支持Xcode設置中的所有方向,除了顛倒。
我用來呈現視圖控制器的代碼
ViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"VC"];
vc.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController:vc animated:YES completion:nil];
我正在使用的代碼允許顯示視圖控制器的方向:
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskAll;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
return YES;
}
你管應用程序在播放視頻時提供相同的功能,任何想法它是如何工作的?
任何幫助都會感謝,謝謝。
AppDelegate.m
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
if(_isAllModes)
return UIInterfaceOrientationMaskAll;
else
return UIInterfaceOrientationMaskPortrait;
}
你的ViewController。 回轉:
[(AppDelegate*)([UIApplication sharedApplication].delegate) setIsAllModes:YES];
NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
[[UIDevice currentDevice] setValue:value forKey:@"orientation"];
我有類似的問題,但項目設置會覆蓋您以編程方式應用的單個ViewController設置。 我為解決這個問題所做的是在項目設置中留下唯一最小的可接受方向,並在AppDelegate.m中擴展它,如下所示
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window //newUX
{
return UIInterfaceOrientationMaskAll;
}
無論如何,你可以做得更好,例如,如果你想只在一個特定場景中啟用所有方向,只要說一下堆棧中的最后一個viewController是否為“all”-one,如下所示
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window //newUX
{
if([self.navController.viewControllers.lastObject isKindOfClass:[MyAllOrientationVC class]])//newUX
return UIInterfaceOrientationMaskAll;
else
return UIInterfaceOrientationMaskPortrait|UIInterfaceOrientationMaskLandscapeLeft|UIInterfaceOrientationMaskLandscapeRight;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.