天天看點

iOS 适應橫屏時遇到的問題

 适應橫屏要求重新布局,這裡涉及到擷取系統橫屏還是豎屏的方法,開始我用的這個方法

-(void)willAnimateSecondHalfOfRotationFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation duration:(NSTimeInterval)duration後來發現這個方法隻到5.0  

- (void)willAnimateSecondHalfOfRotationFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation duration:(NSTimeInterval)duration NS_DEPRECATED_IOS(2_0, 5_0) __TVOS_PROHIBITED; // A this point, our view orientation is set to the new orientation.

然後,就開始看uiviewcontrollor的api  找到了下面這個方法

// Notifies when rotation begins, reaches halfway point and ends.

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration NS_DEPRECATED_IOS(2_0,8_0, "Implement viewWillTransitionToSize:withTransitionCoordinator: instead") __TVOS_PROHIBITED;

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation NS_DEPRECATED_IOS(2_0,8_0) __TVOS_PROHIBITED;

will方法是将要旋轉時調用的  did方法是旋轉結束調用的,

這兩個方法最容易出錯的地方就是擷取狀态和螢幕寬度不同,will方法擷取的的上一個狀态的螢幕寬度,did則是目前狀态的寬度.這裡重新布局很容易出

UIInterfaceOrientationPortraitUpsideDown

其實這裡我有一點沒弄明白 就是這個狀态

UIInterfaceOrientationPortraitUpsideDown  //home button on the top 

這個狀态 我做了判斷但還是不會調用該狀态的方法, 就好像系統未識别一樣,

不知道是不是蘋果不支援倒立豎直狀态.