2015-07-06 25 views
1

先生,iOS强制景观在一个视图控制器

我工作的mapview模块,景观是唯一的方向允许,但其他只有肖像。当在设备ios 7和8上运行时,视图控制器仍以纵向显示,除非我必须手动将设备转为横向。你能告诉我还有其他的步骤吗?

下面是我的代码

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; 
} 

PreviousController.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]; 
} 

的MapViewController

- (BOOL) shouldAutorotate { 
    return YES; 
} 


- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { 
    return UIInterfaceOrientationLandscapeRight; 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight|| interfaceOrientation == UIInterfaceOrientationLandscapeLeft); 
} 

回答

-1

如果要在某些视图控制器中禁用或启用特定方向,那么this可能对您有所帮助。

如果你想打开特定方向的一些看法,然后在viewDidLoad中

NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait]; 
    [[UIDevice currentDevice] setValue:value forKey:@"orientation"]; 
+0

仍然画像,没有使用 –

+0

我使用谷歌地图和谷歌地图使它成为肖像。我不太确定我应该在pinfo.list –

+0

@RjujuGujarati中添加哪些关键/值,你是否改变'UIInterfaceOrientationLandscapeLeft'而不是'UIInterfaceOrientationPortrait'。 –

0

有一个技巧,真正的作品使用。 您可以访问状态栏并设置其方向。下次以模态方式显示视图时,这变为活动状态。 但是,在模态显示后,您可以删除模态显示的视觉控制器。当你在同一个方法内完成时,用户不会注意到任何东西。 现在该设备具有所需的方向。您现在可以安全地推动您想要处于另一个方向的视图控制器。

当从视图控制器返回时,不要忘记将其旋转回来!

请参阅此问题的答案。它带有一些代码sniplets。 Force controllers to Change their orientation in Either Portrait or Landscape

相关问题