2013-03-13 161 views
0

我想這取決於用戶在哪裏我的應用程序支持的方向來定義,我有一個非常困難的時期這樣做。shouldAutorotate不會被調用

到目前爲止,我已經發現我應該使用iOS6中現在支持的supportedInterfaceOrientationsForWindow:和shouldAutorotate方法,但是無論哪種方法在我的UIViewController中定義它們時都不會調用。

這是我的代碼是什麼樣子

- (BOOL)shouldAutorotate { 
    return YES; 
} 

- (NSUInteger)supportedInterfaceOrientationsForWindow { 
    return UIInterfaceOrientationMaskPortrait; 
} 

在我的目標概要支持Orientatoin我已經取消選擇所有選項..想,我只想在每個m ViewControllers的定義支持的方向...我會想知道這是否是正確的事情?

enter image description here

現在我已經讀什麼,我試圖做的是依賴於我的應用程序的藥結構,所以在這裏,我將概述我的應用程序。

  • 主要的UIViewController(3個按鈕帶你到(3個不同的navigationControllerViews)錯了!只有一個navigationController ......對不起它以來我看着這個代碼很長一段時間。)
  • 次要的UIViewController(持有導航控制器)
  • 其他UIViewControllers(出現在secondarys NavigationController)

我想每一個的ViewController起來,直到最後一個在NavigationController堆出現在portrate。 NavigationController中的最後一個視圖是一個特殊的視圖,需要時可以將其方向旋轉到左側或右側。

我想知道這是可能的,如果是這樣,爲什麼心不是我有上面的工作代碼/被調用。

任何幫助將不勝感激。

//更新質疑回覆:

RootView負載與(三個按鈕,這裏是當選擇一個按鈕,被稱爲加載包含導航控制器視圖的方法)

- (IBAction)buttonClick: (UIButton *) sender 
{ 
//.. 

    // v -----> 
    if ([sender isEqual:vUIButton]) { 


     VSearchViewController *vSearchViewController = [[VSearchViewController alloc] initWithNibName:@"VSearchViewController" bundle:nil]; 
     [self.navigationController pushViewController:vehicalSearchViewController animated:YES]; 
    } 
//.. 
} 

然後裏面VSearchViewController我加載到UINavigation堆棧這樣

//.. 
FModelsViewController *fModelsViewController = [[FModelsViewController alloc] initWithNibName:@"FModelsViewController" bundle:nil]; 

      // Sets the back button for the new view that loads (this overrides the usual parentview name with "Back") 
      self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Back" style: UIBarButtonItemStyleBordered target:nil action:nil]; 

      [self.navigationController pushViewController:fModelsViewController animated:YES]; 
//.. 

所以在檢討,我已經設置了導航控制器的新觀點在的appDelegate和我的應用程序的所有意見都在navigationStack ......我錯在說有3個NavigationControllers ..只有一個,每個視圖添加到堆棧..我們對此深感抱歉..它已經有一年因爲我看着這個代碼半..

回答

1

是否運行在iOS6的上面的代碼?這些方法只能在iOS6上調用。

而且也許你可以張貼一些代碼來更好地說明你是如何過渡到這些viewControllers所以我們可以更好地瞭解視圖層次結構。

你可能想看看UIViewController的addChildViewController:方法。

+0

沒關係,我會後的過渡代碼..我的應用程序正在變成升技獸的不少意見,由於我想代表數據的複雜性。我會在幾分鐘內更新我的問題..我會盡我所能提供您需要的信息。 (是,我正在部署到iOS6,它在「目標」>「iosApplication目標」>「部署目標」中正確定義?)。 – HurkNburkS 2013-03-13 21:40:57

+0

你需要確保你在ios6模擬器上運行它。僅僅因爲你的部署目標是6並不意味着你在6上運行它。 – 2013-03-13 21:44:24

+0

是我在我的ios6設備上運行。另外我已經更新了一些代碼。 – HurkNburkS 2013-03-13 22:03:02

0

我認爲你最後的觀點可以採取下面寫的代碼的優勢。它會感應設備的方向,並會爲橫向視圖顯示不同的視圖控制器(我假設這是您正在嘗試執行的操作)。這意味着你的最後一個視圖將有一個肖像和一個風景選項。

@implementation LastViewController 

- (void)awakeFromNib 
{ 
isShowingLandscapeView = NO; 
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; 
[[NSNotificationCenter defaultCenter] addObserver:self 
         selector:@selector(orientationLastViewChanged:) 
         name:UIDeviceOrientationDidChangeNotification 
         object:nil]; 
} 
- (void)orientationLastViewChanged:(NSNotification *)notification 
{ 

UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation; 
if (UIDeviceOrientationIsLandscape(deviceOrientation) && 
!isShowingLandscapeView) 
{ 
[self performSegueWithIdentifier:@"LandscapeLastView" sender:self]; 
isShowingLandscapeView = YES; 
} 
else if (UIDeviceOrientationIsPortrait(deviceOrientation) && 
    isShowingLandscapeView) 
{ 
[self dismissViewControllerAnimated:YES completion:nil]; 
isShowingLandscapeView = NO; 

} 

} 
在視圖控制器導致這一觀點,即你想鎖定肖像

,寫這樣的代碼:

- (BOOL)shouldAutorotate { 
return NO; 
} 

爲您支持的接口方向,離開你如何擁有它。

+0

那麼你說的最後一個視圖會有不同的.xib文件?那是對的嗎? – HurkNburkS 2013-03-13 22:05:48

+0

是的,但實際上我的答案假設你正在使用故事板。注意performSegueWithIndetifier方法。這是在故事板中完成的。你最後一個視圖需要2個不同的視圖控制器(一個是縱向,一個是橫向)。你會有一個連接肖像與景觀的連線,另一個連接景觀與肖像。 – iOSAppGuy 2013-03-13 22:30:37

+0

right ..不幸的是,這種方法不會爲我工作(我知道自私的權利!大聲笑)..我的最後一個看法是如此錯綜複雜,我想這將是幾乎不可能得到這個工作內部允許我不允許重寫視圖...但是非常感謝你的回答,如果結果證明它是實現我所追求的結果的唯一方法,我會更多地考慮它。 – HurkNburkS 2013-03-13 22:38:24