diff --git a/main/Common Classes/SlideInAnimation.swift b/main/Common Classes/SlideInAnimation.swift index a5d3c19..7f51871 100644 --- a/main/Common Classes/SlideInAnimation.swift +++ b/main/Common Classes/SlideInAnimation.swift @@ -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)) } } diff --git a/main/Extensions/View.swift b/main/Extensions/View.swift index 57b89f1..cdb52cb 100644 --- a/main/Extensions/View.swift +++ b/main/Extensions/View.swift @@ -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 {