When should translatesAutoresizingMaskIntoConstraints be set to true?

translatesAutoresizingMaskIntoConstraints needs to be set to false when: You Create a UIView-based object in code (Storyboard/NIB will set it for you if the file has autolayout enabled), And you want to use auto layout for this view rather than frame-based layout, And the view will be added to a view hierarchy that is using auto … Read more

Proportional height (or width) in SwiftUI

UPDATE If your deployment target at least iOS 16, macOS 13, tvOS 16, or watchOS 9, you can write a custom Layout. For example: import SwiftUI struct MyLayout: Layout { func sizeThatFits(proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) -> CGSize { return proposal.replacingUnspecifiedDimensions() } func placeSubviews(in bounds: CGRect, proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) … Read more

AutoLayout views make app crash on popViewController

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) … Read more

Resize the screen when keyboard appears

2020 UPDATE Correctly using a constraint… There is only one way to properly handle this mess in iOS. Paste KUIViewController below in to your project, Create a constraint which is very simply to the “bottom of your content”. Drag that constraint to bottomConstraintForKeyboard KUIViewController will automatically and correctly resize your content view at all times. … Read more