fittingSize()
This commit is contained in:
@@ -172,18 +172,10 @@ private class StickyPresentationController: UIPresentationController {
|
||||
let preferred = presentedViewController.preferredContentSize
|
||||
switch stickTo {
|
||||
case .left, .right:
|
||||
let fitted = target.systemLayoutSizeFitting(
|
||||
CGSize(width: preferred.width, height: full.height),
|
||||
withHorizontalFittingPriority: .fittingSizeLevel,
|
||||
verticalFittingPriority: .required
|
||||
)
|
||||
let fitted = target.fittingSize(fixedHeight: full.height, preferredWidth: preferred.width)
|
||||
return CGSize(width: min(fitted.width, full.width), height: full.height)
|
||||
case .top, .bottom:
|
||||
let fitted = target.systemLayoutSizeFitting(
|
||||
CGSize(width: full.width, height: preferred.height),
|
||||
withHorizontalFittingPriority: .required,
|
||||
verticalFittingPriority: .fittingSizeLevel
|
||||
)
|
||||
let fitted = target.fittingSize(fixedWidth: full.width, preferredHeight: preferred.height)
|
||||
return CGSize(width: full.width, height: min(fitted.height, full.height))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,18 @@ extension UIView {
|
||||
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 {
|
||||
|
||||
Reference in New Issue
Block a user