fittingSize()
This commit is contained in:
@@ -172,18 +172,10 @@ private class StickyPresentationController: UIPresentationController {
|
|||||||
let preferred = presentedViewController.preferredContentSize
|
let preferred = presentedViewController.preferredContentSize
|
||||||
switch stickTo {
|
switch stickTo {
|
||||||
case .left, .right:
|
case .left, .right:
|
||||||
let fitted = target.systemLayoutSizeFitting(
|
let fitted = target.fittingSize(fixedHeight: full.height, preferredWidth: preferred.width)
|
||||||
CGSize(width: preferred.width, height: full.height),
|
|
||||||
withHorizontalFittingPriority: .fittingSizeLevel,
|
|
||||||
verticalFittingPriority: .required
|
|
||||||
)
|
|
||||||
return CGSize(width: min(fitted.width, full.width), height: full.height)
|
return CGSize(width: min(fitted.width, full.width), height: full.height)
|
||||||
case .top, .bottom:
|
case .top, .bottom:
|
||||||
let fitted = target.systemLayoutSizeFitting(
|
let fitted = target.fittingSize(fixedWidth: full.width, preferredHeight: preferred.height)
|
||||||
CGSize(width: full.width, height: preferred.height),
|
|
||||||
withHorizontalFittingPriority: .required,
|
|
||||||
verticalFittingPriority: .fittingSizeLevel
|
|
||||||
)
|
|
||||||
return CGSize(width: full.width, height: min(fitted.height, full.height))
|
return CGSize(width: full.width, height: min(fitted.height, full.height))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,18 @@ extension UIView {
|
|||||||
return UIImage(cgImage: image!.cgImage!)
|
return UIImage(cgImage: image!.cgImage!)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Find size that fits into frame with given `width` as precondition.
|
||||||
|
/// - Parameter preferredHeight:If unset, find smallest possible size.
|
||||||
|
func fittingSize(fixedWidth: CGFloat, preferredHeight: CGFloat = 0) -> CGSize {
|
||||||
|
systemLayoutSizeFitting(CGSize(width: fixedWidth, height: preferredHeight), withHorizontalFittingPriority: .required, verticalFittingPriority: .fittingSizeLevel)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Find size that fits into frame with given `height` as precondition.
|
||||||
|
/// - Parameter preferredWidth:If unset, find smallest possible size.
|
||||||
|
func fittingSize(fixedHeight: CGFloat, preferredWidth: CGFloat = 0) -> CGSize {
|
||||||
|
systemLayoutSizeFitting(CGSize(width: preferredWidth, height: fixedHeight), withHorizontalFittingPriority: .fittingSizeLevel, verticalFittingPriority: .required)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension UIEdgeInsets {
|
extension UIEdgeInsets {
|
||||||
|
|||||||
Reference in New Issue
Block a user