Shoehorn the controller into the little area allowed for context previews in landscape. Issue #1569

This commit is contained in:
Maurice Parker 2020-01-09 21:11:13 -07:00
parent 614b24dc0e
commit 1b1b3e796e
1 changed files with 16 additions and 1 deletions

View File

@ -42,9 +42,24 @@ class ContextMenuPreviewViewController: UIViewController {
dateFormatter.timeStyle = .medium dateFormatter.timeStyle = .medium
dateTimeLabel.text = dateFormatter.string(from: article.logicalDatePublished) dateTimeLabel.text = dateFormatter.string(from: article.logicalDatePublished)
// When in landscape the context menu preview will force this controller into a tiny
// view space. If it is documented anywhere what that is, I haven't found it. This
// set of magic numbers is what I worked out by testing a variety of phones.
let width: CGFloat
let heightPadding: CGFloat
if view.bounds.width > view.bounds.height {
width = 260
heightPadding = 16
view.widthAnchor.constraint(equalToConstant: width).isActive = true
} else {
width = view.bounds.width
heightPadding = 8
}
view.setNeedsLayout() view.setNeedsLayout()
view.layoutIfNeeded() view.layoutIfNeeded()
preferredContentSize = CGSize(width: view.bounds.width, height: dateTimeLabel.frame.maxY + 8) preferredContentSize = CGSize(width: width, height: dateTimeLabel.frame.maxY + heightPadding)
} }
} }