Slide 48
Slide 48 text
UIViewRepresentable — ϨΠΞτ
• UIView ͷ systemLayoutSizeFitting ͳͲΛͬͯ൚༻తͳαΠζܭࢉΛ࣮Ͱ͖Δ
func sizeThatFits(_ proposal: ProposedViewSize, uiView: UIViewType, context: Context) -> CGSize? {
let widthTarget = target(for: proposal.width)
let heightTarget = target(for: proposal.height)
return uiView.systemLayoutSizeFitting(
CGSize(width: widthTarget.0, height: heightTarget.0),
withHorizontalFittingPriority: widthTarget.1,
verticalFittingPriority: heightTarget.1
)
}
func target(for proposal: CGFloat?) -> (CGFloat, UILayoutPriority) {
switch proposal {
case .none: return (UIView.layoutFittingCompressedSize.width, .fittingSizeLevel)
case .some(.zero): return (UIView.layoutFittingCompressedSize.width, .defaultHigh)
case .some(.infinity): return (UIView.layoutFittingExpandedSize.width, .defaultLow)
case let .some(value): return (value, .defaultHigh)
}
}
• ܕใ͕͋Δ͔Βɺͦͷ UIView (UIViewController) ʹಛԽͨ͠ܭࢉ࣮Ͱ͖Δ
※ ίʔυΠϝʔδͰ͢