Can I use autolayout to provide different constraints for landscape and portrait orientations?

后端 未结 6 1886
旧巷少年郎
旧巷少年郎 2020-12-01 03:44

Is it possible to change the constraints when the device is rotated? How might this be achieved?

A simple example might be two images which, in portrait, are stacked

6条回答
  •  一向
    一向 (楼主)
    2020-12-01 04:20

    You can save your constraints, to a property or variable as portrait and landscape versions then set and remove them on rotate.

    I have done this making my constraints in xib for initial view, assigning them to outlets in the view controller. On rotate I create the alternate restraints, remove the outlets but retain them, insert the alternates.

    Reverse the process on rotate back.

提交回复
热议问题