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
Indeed, this must be OS (iOS 7) bug. I've spent few days debugging autolayout collapsing totally (note: NO NSLayout exceptions). I've almost collapsed too.
It was ALL due to using some combinations of constraints together with aspect-ratio constraints.
I am solving this with redesigning UI...Pain.
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)
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.
I resolved it You don't set ratio itself. You should set equal with its container But better you should set height constraint follow iPhone 6. You must outlet constrain in your class. In viewDidLoad you must multiplier with DISPLAY_SCALE
DISPLAY_SCALE = UIScreen.mainScreen().bounds.width / 375
// 375 is width of iPhone 6.
Why do you must do that? I think iOS7 delay when calculator our constraint. And it wrong when show
This is one annoying bug, cost me a lot of hours as well. I had the exact same problem, the app was working fine in iOS 8 but crashed in iOS 7.1. The problem was an aspect ratio constraint on a scroll view. After trying out a lot of different things, this finally solved the problem:
The crash seems to be the result of a floating point calculation that fails at some point. In my case, I had defined an aspect ratio of 16:9 or rather 9:16, which amounts to 0.5625. Changing the multiplier from 0.5625 to 0.5624 fixed the problem, no more crashes have appeared since then.
I had this crash on iOS7 when I had a combination of aspect ratio, equal height to container, and zero top and bottom spacing to container constraints. The equal height to container constraint was redundant as it was constrained to the top and bottom of the container so I removed it and the crash stopped. It must be a bug in the OS.