iOS force landscape in one viewController

标签 ios objective-c uiinterfaceorientation

先生,

我正在开发 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/

相关文章:

ios - 底部UITableView隐藏时如何让UIScrollView占据屏幕高度?

objective-c - 子类化您自己的类之一还是使用相同的父类?

ios - 将 View 动画化到 collectionView 中的选定单元格或 scrollView 中的 tableView

swift - 改变方向时应用程序会更改为不同的 Controller View

ios - iphone 应用程序中单个 viewController 的横向方向

ios - 我怎样才能拥有类似于AirBNB iOS App上的UIScroll效果,如下图所示

objective-c - UIView 中的 UIImageView 而不是越界显示图像部分

ios - 使用目标选择器保留循环

ios - uipageViewController 没有加载 y=0 的 View

iOS UIInterfaceOrientation