iOS View不會隨著機子旋轉


翻轉螢幕後VIEW無法跟著同步旋轉的問題
有時是重繪問題 有時是VIEW繼承問題
我的tabbar有多个tabview,当我进行旋转的时候,当前的view能够接受到旋转事件,但其他几个view无法接受到,导致我切换view时其他view的rect还是原大小,不知道该如何解决呢?

翻轉螢幕會觸發shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation與willAnimateRotationToInterfaceOrientation事件 可在事件裡面增加:
  
[self.viewController willAnimateRotationToInterfaceOrientation:
 toInterfaceOrientation duration:duration];  
如果是選轉後大小跑掉可以在在shouldAutorotateToInterfaceOrientation重設
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
   重設你的元件大小或是設定 
   return YES;
}
另外一種View不會選轉的可能性
參考[1]   在UIWindow中添加了兩個ViewController,並顯示後一個ViewController的視圖,結果視圖並沒有被旋轉成橫版,仍舊按照豎版來顯示。Google和StackOverFlow了一把,發現很多人都碰到過類似的問題,比如這個和這個。當然也有人給出了解決方案:給UIWindow設置一個rootViewController,爾後添加的所有ViewController都以rootViewController的subview形式添加。



See Also:
  1. iOS View事件處理流程
  2. 什么样的UIViewController具有响应屏幕旋转事件的权限 

留言

這個網誌中的熱門文章

Office 2021 離線安裝封裝與KMS啟動步驟

Ollama使用心得與模型導入教學

ARC下NSMutableDictionary 無法使用retainCount