2017-09-07 39 views
0

我想實現在縱向上的iPhone如下:獲取矩形,以兩種不同的方式佈局,自動佈局

enter image description here

,並在iPhone上的景觀以下,或iPad縱向/橫向: enter image description here

任何人都會根據新的尺寸類別和自適應佈局功能爲您提供建議,以瞭解如何執行此操作?

也許我需要根據大小類創建兩個自動佈局約束框#4(第二行中的第一個框)?因此,如果它的高度緊湊,但寬度一般,那麼優先級較高的類橫向約束還是有些什麼的?我很難與此=/

非常感謝!

回答

0

我認爲你可以通過創建2組約束來實現這一點,第一組將處理以適合iPhone的方式查看矩形,並且它的約束優先級較低(例如1),而第二組將負責以適合iPad的方式查看矩形,並且其約束具有高優先級(例如999)。

現在,您需要以編程方式檢查設備類型並確定要激活的一組合適的約束條件。

if UIDevice.current.userInterfaceIdiom == .pad { 

    // Set high priorities for the set of constraints that takes care of viewing the rectangles in the suitable way for iPad and low priorities for iPhone set. 

} else { 

    // Set high priorities for the set of constraints that takes care of viewing the rectangles in the suitable way for iPhone and low priorities for iPad set. 
}