2012-10-01 45 views
0

在iOS中,手動旋轉視圖的正確方法是什麼?我有很多自定義旋轉動畫,我不希望我的視圖自動旋轉。手動旋轉UIViews而不是自動旋轉

現在,我這樣做...

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    // Return YES for supported orientations 
    return interfaceOrientation == UIDeviceOrientationPortrait; 
} 

然後,我這樣做,並根據需要應對方向變化:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil]; 

一切工作正常,但...當我嘗試呈現操作表,一個MailViewController等,他們都顯示在縱向:(

我怎樣才能讓我的看法知道,雖然我不想它自動旋轉,它是在事實上應對我手動處理的方向通知?

編輯:爲了澄清,這不是我的旋轉不起作用,而是當我提交一個UIActionSheet時,它假定我必須是肖像(即使當我手動旋轉以至於我不是)時,並顯示不正確。

回答

1

嘗試使用[[UIApplication sharedApplication] setStatusBarOrientation:(UIInterfaceOrientation)];當你manualy旋轉視圖

+0

哇真棒,謝謝一堆!有趣的故事......我最近做了大量的代碼重組/清理工作,並且想到了它(並且通過我的git歷史證實了這一點),我曾經在我的代碼中擁有這行代碼,但因爲我不記得原因它在那裏!我不會再忘記這段代碼的目的,哈哈。 – MikeS

+0

(尤其是因爲這次有詳細的評論) – MikeS

0

也許你可以從shouldAutorotateToInterfaceOrientation中調用方法。 例如:

- (BOOL)shouldAutorotateToInterfaceOrientation (UIInterfaceOrientation)interfaceOrientation 
{ 
    if (interfaceOrientation != UIDeviceOrientationPortrait) 
     [self theActionYouWantToPerform] 

    // Return YES for supported orientations 
    return interfaceOrientation == UIDeviceOrientationPortrait; 
} 
+0

謝謝,但問題不是我的輪換不工作。這就是說,我的UIView沒有意識到它甚至沒有被旋轉(因爲我返回「interfaceOrientation == UIDeviceOrientationPortrait」),所以UIActionSheets和MailComposer自動顯示在父視圖的方向上,總是以縱向顯示,即使我手動旋轉我的視圖,以免它看起來像是在肖像。 – MikeS

0

安東ķ報告的線

[[UIApplication sharedApplication] setStatusBarOrientation:(UIInterfaceOrientation)]; 

作品我沒問題!當我想使用CGAFFineTransformMakeRotation方法手動旋轉UIViewController的UIView以旋轉視圖PI/2弧度時,IT是否僅僅是休息我的元素。

這條線,設置狀態欄的方向你想要的(UIInterfaceOrientation),用於製造UIView的完美呈現「手動」旋轉到(UIInterfaceOrientation)我想要的。

結果,這條線也使得UIMessageView的進一步介紹,它出現在(UIInterfaceOrientation)你指示。