[英]Force UIViewController full screen and landscape
如何在iOS中強制其中一個視圖控制器變為全屏和橫向顯示? 我的應用程序處於縱向模式,但我只希望其中一種視圖是橫向和全屏。
我嘗試了以下解決方案 ,該解決方案包括使用以下方法實現CustomUINavigationController並在要旋轉的viewcontroller中添加shouldAutorotate方法:
//自定義UINAvigationController
-(NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskLandscapeRight;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
return UIInterfaceOrientationLandscapeRight;
}
- (BOOL)shouldAutorotate{
return YES;
}
//我要自動旋轉的UIViewController
- (NSUInteger)supportedInterfaceOrientations
{
return self.topViewController.supportedInterfaceOrientations;
}
我想我的問題與視圖的草率有關。 如果我的ViewController是我的初始視圖控制器,但不是所有視圖都可以,則可以使用。 我有一個自定義菜單和一個占位符(視圖),在其中顯示所有其他視圖。 我想成為橫向和全屏的ViewController來自占位符內部的視圖,也許這是問題所在,但我現在不解決該問題。
因此,當調用viewController來表示形式為self時,將調用以下方法:
-(NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskLandscapeRight;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
return UIInterfaceOrientationLandscapeRight;
}
- (BOOL)shouldAutorotate{
return YES;
}
如您所見,通過放置它們,我強制UIViewContoller顯示LandscapeRight。
重要的不是! :如果使用UINavigation控制器,則需要創建一些“主”導航控制器子視圖,然后在其中調用這些方法。
希望這可以幫助!
您可以使用我的LNWindowManager
在其他窗口中以模態形式顯示視圖控制器。
https://github.com/LeoNatan/LNWindowManager
它向模態視圖控制器表示提供了類似的API,但已擴展到Windows:
- (IBAction)displayButtonTapped:(UIButton *)sender
{
UINavigationController* nvc = [self.storyboard instantiateViewControllerWithIdentifier:@"__presentationNVC"];
nvc.topViewController.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(dismissWindow:)];
UIWindow* window = [LNWindowManager templateWindowForName:@"example"];
window.rootViewController = nvc;
[[LNWindowManager sharedWindowManager].topWindow presentWindow:window animated:YES completion:nil];
}
- (void)dismissWindow:(UIBarButtonItem*)barButtonItem
{
[[LNWindowManager sharedWindowManager].topWindow.presentingWindow dismissWindow:[LNWindowManager sharedWindowManager].topWindow animated:YES completion:nil];
}
然后,可以使用AppDelegate方法確定每個窗口的方向:
– application:supportedInterfaceOrientationsForWindow:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.