先生,
我正在开发 mapview 模块,其中横向是唯一允许的方向,而其他方向仅适用于纵向。当谈到在设备 ios 7 和 8 上运行时, View Controller 仍然显示为纵向,除非我必须手动将设备转为横向。你能告诉我还有哪些其他步骤要做吗?
下面是我的代码
AppDelegate.h
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (nonatomic) BOOL isTaskPoint;
@end
AppDelegate.m
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if (UIInterfaceOrientationIsPortrait(interfaceOrientation)) return YES;
return NO;
}
上一个Controller.m
MapViewController * sliderVC = [[MapViewController alloc] init ];
AppDelegate *appDelegate = (AppDelegate *) [UIApplication sharedApplication].delegate;
appDelegate.isTaskPoint = TRUE;
sliderVC.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentViewController:sliderVC animated:NO completion:nil];
sliderVC.view.backgroundColor = [UIColor clearColor];
// MapSwift maps =
MapViewController.h
- (void)bannerTapped:(UIGestureRecognizer *)gestureRecognizer {
AppDelegate *appDelegate = (AppDelegate *) [UIApplication sharedApplication].delegate;
appDelegate.isTaskPoint = FALSE;
[self dismissViewControllerAnimated: NO completion:nil];
}
map View Controller
- (BOOL) shouldAutorotate {
return YES;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationLandscapeRight;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight|| interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}
最佳答案
只有一种技巧非常管用。 您可以访问状态栏并设置其方向。下次以模态方式显示 View 时,它将变为事件状态。 但是,在模态显示之后,您可以立即删除模态显示的 View Controller 。当您在相同的方法中执行此操作时,用户将不会注意到任何事情。 现在设备具有所需的方向。您现在可以安全地将您想要的 View Controller 推向另一个方向。
从那个 View Controller 返回时,不要忘记将它旋转回来!
查看此问题的答案。它带有一些代码片段。 Force controllers to Change their orientation in Either Portrait or Landscape
关于iOS force landscape in one viewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31244891/