我正在开发一个用户将观看直播 channel 的项目。但是我在这里遇到了一个小问题,我已经非常努力地尝试但没有找到任何解决方案。我的应用程序将支持除最后一个 View 之外的所有 View 的纵向方向。最后一个 View 将仅支持横向。是否可以? 我搜索并尝试了以下代码
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait];
//
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];
//
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);}
最佳答案
关注this link .希望你能在这里得到答案。
该链接显示了如何将所有 View 保持为纵向模式,但一个 View 将处于横向模式。
您需要执行以下操作:
第一:
在所有为肖像修复的 Controller 中实现这一点:
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
并为景观 Controller 实现这个:
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
第二:
// Fetch the status bar from the app and set its orientation as required.
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:YES];
// Create an empty view controller, present it modally and remove it directly afterwards
UIViewController *mVC = [[UIViewController alloc] init];
[self presentModalViewController:mVC animated:NO];
[self dismissModalViewControllerAnimated:NO];
// Now the device is rotated to the desired orientation. Go from there.
希望有用。
关于ios - 将一个 View 方向更改为横向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23992792/