AutoLayout views make app crash on popViewController

前端 未结 5 851
悲哀的现实
悲哀的现实 2020-12-03 16:18

Final Update - Fixed

I have fixed this. It seems that while playing around (this is my first project in Swift and using AutoLayout) I have changed t

5条回答
  •  -上瘾入骨i
    2020-12-03 16:43

    Just putting this here in case anyone has the same issue with a dynamic, code-generated aspectRatio constraint. I switched the order of the Height and Width relationship in the aspect-ratio constraint (compare to the one in the question):

    aspectConstraint = NSLayoutConstraint(item: cardMedia, attribute: NSLayoutAttribute.Height , relatedBy: NSLayoutRelation.Equal, toItem: cardMedia, attribute: NSLayoutAttribute.Width, multiplier: aspect, constant: 0.0)
    

    Where the multiplier aspect is calculated by:

    let aspect = image.size.height / image.size.width
    

    And that seems to stop the crash from happening. Hope this helps someone.

提交回复
热议问题