iOS aspect ratio constraint breaks on iOS7, works on iOS8

前端 未结 6 1750
春和景丽
春和景丽 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:21

    I have this problem with NSLayoutConstraint and multiplier on iOS 7. Works perfectly on iOS 8.

    I'm using multiplier with value 0.2 and it causes errors!

    NSLayoutConstraint(item: BT_Facebook,
                  attribute: NSLayoutAttribute.Width,
                  relatedBy: .Equal,
                     toItem: nil,
                  attribute: .Width,
                 multiplier: 0.2,
                   constant: sizeBtRedeSociais)
    

    The solution is to use the size of the screen, and not percentages.

    var sizeBtRedeSociais = UIScreen.mainScreen().bounds.width / 5
    var BT_FacebookWidth = NSLayoutConstraint(item: BT_Facebook, attribute: NSLayoutAttribute.Width, relatedBy: .Equal, toItem: nil, attribute: .Width, multiplier: 1, constant: sizeBtRedeSociais)
    var BT_TwitterWidth = NSLayoutConstraint(item: BT_Twitter, attribute: NSLayoutAttribute.Width, relatedBy: .Equal, toItem: nil, attribute: .Width, multiplier: 1, constant: sizeBtRedeSociais)
    var BT_InstagramWidth = NSLayoutConstraint(item: BT_Instagram, attribute: NSLayoutAttribute.Width, relatedBy: .Equal, toItem: nil, attribute: .Width, multiplier: 1, constant: sizeBtRedeSociais)
    var BT_GoogleWidth = NSLayoutConstraint(item: BT_Google, attribute: NSLayoutAttribute.Width, relatedBy: .Equal, toItem: nil, attribute: .Width, multiplier: 1, constant: sizeBtRedeSociais)
    var BT_YoutubeWidth = NSLayoutConstraint(item: BT_Youtube, attribute: NSLayoutAttribute.Width, relatedBy: .Equal, toItem: nil, attribute: .Width, multiplier: 1, constant: sizeBtRedeSociais)
    

提交回复
热议问题