Programmatically implementing two different layouts using size classes

前端 未结 4 1704
清歌不尽
清歌不尽 2021-01-30 16:54

I have a four buttons layout. In portrait they should be shown one above the other. In landscape they should be in two columns each with two buttons.

I implement the but

4条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-30 17:06

    You can examine the view's trait collection to determine its horizontal and vertical size class.

    if (self.view.traitCollection.horizontalSizeClass == UIUserInterfaceSizeClassCompact) {
        ...
    }
    

    Implement the traitCollectionDidChange: method to automatically be called when a trait changes due to autorotation.

    For more information, see UITraitCollection Class Reference and UITraitEnvironment Protocol Reference.

提交回复
热议问题