2014-12-13 116 views
4

我爲Deployment target> = 7.1創建應用程序。我看到「bug」... 應用程序只在橫向模式下運行!iOS7和iOS8返回的不同UIScreen界限

代碼:

CGSize frameSize = [[UIScreen mainScreen] bounds].size; 

在iOS系統7(iPhone 4),返回CGSize (width=320, height=480),但必須返回480x320(因爲在橫向模式下運行應用程序)。 在iOS 8(iPhone 4S)中,返回CGSize (width=480, height=320) - 正確的結果。

iOS 7返回幀時沒有選中橫向/縱向模式,並返回縱向模式的大小。

謝謝。

回答

6

行爲在IOS 8.

改變報價UIScreen文檔

在此之前的iOS 8,屏幕的邊界矩形總是反映相對於縱向向上取向的屏幕尺寸。將設備旋轉至風景或顛倒方向不會改變邊界。在iOS 8和更高版本中,屏幕的邊界屬性會考慮屏幕的界面方向。此行爲意味着縱向方向上設備的界限可能與橫向方向上設備的界限不同。依賴屏幕尺寸的應用程序可以使用fixedCoordinateSpace屬性中的對象作爲必須制定的任何計算的固定參照點。

+0

謝謝,不知道 – ZhukV 2014-12-13 14:11:06

6

是的,有在API變化爲iOS 8

是的,它的方向依賴於iOS8上,而不是一個錯誤。你可以從WWDC 2014檢討會議214更多信息: 「View Controller Advancements in iOS 8」 從表現

報價:

UIScreen目前接口導向:

[UIScreen bounds] now interface-oriented 
[UIScreen applicationFrame] now interface-oriented 
Status bar frame notifications are interface-oriented 
Keyboard frame notifications are interface-oriented 

可能的複製闕:Is [UIScreen mainScreen].bounds.size becoming orientation-dependent in iOS8?

要達到您的目標,請檢查iOS版本並相應地運行代碼:

How can we programmatically detect which iOS version is device running on?

希望這會有所幫助。

+2

不應該'-convertRect:fromWindow:nil'繼續做正確的事情嗎?如果是這樣,那麼作者不需要使用版本檢查來編寫自己的小自定義轉換代碼。只需使用預期的內置方法? – Tommy 2014-12-13 14:56:35

相關問題