iOS aspect ratio constraint breaks on iOS7, works on iOS8

前端 未结 6 1746
春和景丽
春和景丽 2021-02-04 18:37

In my app, I have setup a UIView\'s constraints in a way where its height gets calculated from its width using the aspect ratio constraint. It works perfectly on iOS8 with every

6条回答
  •  后悔当初
    2021-02-04 19:26

    I resolved it in the following way:

    Assuming my panel will look the same on iPhone 4, 4s, 5, 5s since they have the same width, so their aspect ratio will result in the same height. I added a height constraint to the same view that I added the aspect ratio constraint to. So regardless of the iOS version, on these devices, the view will look right with the height constraint.

    iPhone6 and 6+ only run on iOS8 or higher, where the aspect ratio constraint doesn't fail, I simply delete the height constraint if the iOS version is 8 or higher, else I delete the aspect ratio constraint.

    It's far from being elegant, but solves the issue in an easy way.

提交回复
热议问题