I'm experiencing an intermittent bug with Auto Layout in the popover for Safari App Extensions.
It appears that any resizing in the view controller sometimes happens before the window itself is resized, and this has a very odd appearance. I'd like to figure out how to stop this from happening.
I've tried moving any constraint changes into the updateConstraints
method as suggested in AppKit resources I've found, however the bug remains.
For reference, here are the collapsed and expanded views:
Here are the intermediate frames that I'd like to prevent:
This is the function that toggles the constraints to show/hide the long text:
@objc private func toggleContent(_ sender: NSButton) {
if longText.isDescendant(of: contentView) {
contentButton.title = "Show text"
// Remove text
longText.removeFromSuperview()
initialBottomConstraint.isActive = true
} else {
// Add text
contentButton.title = "Hide text"
initialBottomConstraint.isActive = false
longText.translatesAutoresizingMaskIntoConstraints = false
contentView.addSubview(longText)
NSLayoutConstraint.activate([
longText.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: 16.0),
longText.topAnchor.constraint(equalTo: contentButton.bottomAnchor, constant: 16.0),
longText.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -16.0),
longText.bottomAnchor.constraint(equalTo: contentView.bottomAnchor, constant: -16.0)
])
}
}
Edit: for screenshot size