强制控制器在纵向或横向中更改其方向
我有以下控制器,(我已经选择iPad中的所有类型定向模式)
I have following Controllers, (I have selected all types orientation modes in iPad)
这是我的iPad故事板布局
Here is my iPad Storyboard layout
Custom NavigationController > Loading Ctrl > Main Controller.
我的自定义导航包含
-(BOOL)shouldAutorotate
{
return [[self.viewControllers lastObject] shouldAutorotate];
}
-(NSUInteger)supportedInterfaceOrientations
{
return [[self.viewControllers lastObject] supportedInterfaceOrientations];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}
在我的载入控制器
-(BOOL)shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
if (UIUserInterfaceIdiomPad == UI_USER_INTERFACE_IDIOM())
return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
else
return UIInterfaceOrientationMaskPortrait;
}
supportedInterfaceOrientations像往常一样调用,一切似乎都确定,主控制器使用performSegue
The supportedInterfaceOrientations gets called as usual and everything seems ok, But when I push my Main Controller using performSegue
-(NSUInteger)supportedInterfaceOrientations
{
if (UIUserInterfaceIdiomPad == UI_USER_INTERFACE_IDIOM())
return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
else
return UIInterfaceOrientationMaskPortrait;
}
在MainController中不再调用。为什么呢?
No more calls in MainController. Why is that?
有一个窍门。
从应用程序获取状态栏并旋转它。
Fetch the status bar from the Application and rotate it.
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:YES];
以模式方式创建并显示和关闭空视图控制器。
Create and display and dismiss an empty view controller modally.
UIViewController *mVC = [[UIViewController alloc] init];
[self presentModalViewController:mVC animated:NO];
[self dismissModalViewControllerAnimated:NO];
现在您的设备已被强制旋转。您现在可以切换到适当的视图控制器或使用导航控制器推一个。
Now your device shoud have been forced to rotate. You could now segue to a proper view controller or push one using the navigation controller.