Skip to content

Commit

Permalink
fix: fix vertical flip button icon image issue
Browse files Browse the repository at this point in the history
The image is still not great, but since horizontal flip is usually used, it is good enough for now.
  • Loading branch information
guoyingtao committed Mar 14, 2023
1 parent 88f09a2 commit 643884b
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions Sources/Mantis/CropViewController/ToolBarButtonImageBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,24 +88,22 @@ struct ToolBarButtonImageBuilder {
static func verticallyFlipImage() -> UIImage? {
if #available(macCatalyst 13.1, iOS 13.0, *) {
guard let horizontallyFippedImage = horizontallyFlipImage(),
let cgImage = horizontallyFippedImage.cgImage else {
let cgImage = horizontallyFippedImage.cgImage else {
return nil
}

UIGraphicsBeginImageContextWithOptions(CGSize(width: horizontallyFippedImage.size.height,
height: horizontallyFippedImage.size.width),
false,
horizontallyFippedImage.scale)
let context = UIGraphicsGetCurrentContext()
context?.rotate(by: .pi / 2)
context?.translateBy(x: 0, y: -horizontallyFippedImage.size.height)
context?.draw(cgImage, in: CGRect(x: 0, y: 0, width: horizontallyFippedImage.size.height, height: horizontallyFippedImage.size.width))
let image: UIImage? = UIGraphicsGetImageFromCurrentImageContext()
let rotatedImage = UIImage(cgImage: cgImage, scale: horizontallyFippedImage.scale, orientation: .leftMirrored)

let newSize = CGSize(width: horizontallyFippedImage.size.height, height: horizontallyFippedImage.size.width)
UIGraphicsBeginImageContextWithOptions(newSize, false, horizontallyFippedImage.scale)
rotatedImage.draw(in: CGRect(origin: .zero, size: newSize))

let newImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image

return newImage
}

return nil
}

}

0 comments on commit 643884b

Please sign in to comment.