標籤:ios
(沒有逐字逐詞翻譯,希望能夠理解,如果有不對的,懇請指正)
UIKit
Note注意When linking against iOS 8.3, any code that relies on layout information (such as the frame) of a
UIButton subview when the button is not in the window hierarchy will need to send
layoutIfNeeded to the button before retrieving layout information (such as
button.titleLabel.frame) to ensure that the layout values are up to date.在iOS8.3下編譯連結的時候,如果UIButton(包括子類)不是視窗層級的控制項,任何涉及擷取和操作UIButton(包括子類)布局資訊的代碼,都應該先發送一個layoutIfNeeded事件(其實就是執行UIButton的layoutIfNeed方法),以確保擷取到的UIButton的布局資訊是最新的。
For example, if you had something like this:
舉例如下,如果iOS8.3以前,你這樣寫代碼:
UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem]; |
// code that sets up the button, but doesn’t yet add it to a window |
CGRect titleFrame = button.titleLabel.frame; |
// code that relies on the correct value for titleFrame |
You now need:那麼,現在你需要這樣寫代碼:
UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem]; |
// code that sets up the button, but doesn’t yet add it to a window |
[button layoutIfNeeded]; // This is also safe pre-iOS 8.3 |
CGRect titleFrame = button.titleLabel.frame; |
// code that relies on the correct value for titleFrame |
iOS SDK Release Notes for iOS 8.3 Beta 4 節選(UIKit)