2015-07-06 21 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

相關問題