2012-06-28 43 views
0

嗨,iOS應用方向旋轉鎖定/通過應用程序的配置

我想要實現的方向旋轉鎖定/解鎖功能開關撥到我的iOS應用程序解鎖。

鎖定是確定的,但解鎖是一個問題。

假設應用程序的方向和設備的方向不同。如果用戶在這種情況下解鎖,應用的方向應該立即遵循設備的方向。但我找不到路。

如何模擬設備的方向旋轉?

編輯

我會澄清一下情況。

在應用程序中有一個切換開關,啓用/禁用方向旋轉。

一步一步:

1.開關已啓用。

2.設備旋轉到portlait。

3.對於每個方向,UIViewController的shouldAutorotateToInterfaceOrientation返回YES。

4.應用程序旋轉到portlait。

5.用戶切換開關以禁用。

6.設備旋轉到橫向。

7. UIViewController的shouldAutorotateToInterfaceOrientation返回NO,除了portlait。

8.應用程序不旋轉。

9.用戶切換開關以啓用。

10.應用程序應旋轉到橫向。這就是問題。

+1

等等,你如何鎖定設備的方向? – CodaFi

+0

通過實施shouldAutorotateToInterfaceOrientation。 – user1488065

回答

1

我還沒有嘗試過,但有一個viewController方法attemptRotationToDeviceOrientation(iOS5)。可能值得一試。有趣的問題。報告它是否有效。

// call this method when your return value from shouldAutorotateToInterfaceOrientation: changes 
// if the current interface orientation does not match the current device orientation, 
// a rotation may occur provided all relevant view controllers now return YES from shouldAutorotateToInterfaceOrientation: 
+ (void)attemptRotationToDeviceOrientation __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_5_0); 
+0

它使旋轉。但這種方式有一個問題。當調用UIViewController的didRotateFromInterfaceOrientation時,視圖框架的大小仍然不變。如果設備旋轉,則該值爲新值。 – user1488065

+0

您是否正在根據用戶pref和當前方向更改'shouldAutorotateToInterfaceOrientation'返回的內容?可能需要更多的手段才能實現它 - 不要放棄(然而!-)) –

-1

你可以閱讀「技術問答&一個QA1688」與autoratotion,並在每個視圖 - 控制使消息shouldAutorotateToInterfaceOrientation涉及:返回根據您的開關設置正確的值。你的info.plist中還有一個開關。坊間確保你在這裏正確的設置以及

0

見我的答案在這裏:https://stackoverflow.com/a/13033443/580173

我做了一個自定義的UINavigationController,在那裏你可以檢查中查看你,並與正確的面具迴應。 (我想根視圖是肖像)

- (BOOL)shouldAutorotate { 
    return YES; 
} 

- (NSUInteger)supportedInterfaceOrientations 
{ 
    if([self.viewControllers count] == 1) return UIInterfaceOrientationMaskPortrait; 
    return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscape; 
} 
相關問題