Created
July 3, 2022 20:02
-
-
Save kylehowells/c92bbb7471f8ca919084817113815285 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private func AVMakeRectFill(aspectRatio: CGSize, insideRect boundingRect: CGRect) -> CGRect { | |
let targetSize = boundingRect.size | |
if targetSize == .zero { | |
return .zero | |
} | |
let widthRatio = targetSize.width / aspectRatio.width | |
let heightRatio = targetSize.height / aspectRatio.height | |
let scalingFactor = max(widthRatio, heightRatio) | |
let newSize = CGSize( | |
width: aspectRatio.width * scalingFactor, | |
height: aspectRatio.height * scalingFactor | |
) | |
let origin = CGPoint( | |
x: (targetSize.width - newSize.width) / 2, | |
y: (targetSize.height - newSize.height) / 2 | |
) | |
return CGRect(origin: origin, size: newSize) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment