diff --git a/Demo/SwiftyCropDemo/ContentView.swift b/Demo/SwiftyCropDemo/ContentView.swift index f4e90ee..f4081a2 100644 --- a/Demo/SwiftyCropDemo/ContentView.swift +++ b/Demo/SwiftyCropDemo/ContentView.swift @@ -82,7 +82,7 @@ struct ContentView: View { .frame(maxWidth: .infinity, alignment: .leading) Button { - maskRadius = UIScreen.main.bounds.width / 2 + maskRadius = min(UIScreen.main.bounds.width, UIScreen.main.bounds.height) / 2 } label: { Image(systemName: "arrow.up.left.and.arrow.down.right") .font(.footnote) @@ -135,7 +135,9 @@ struct ContentView: View { // Example function for downloading an image private func downloadExampleImage() async -> UIImage? { - let urlString = "https://picsum.photos/1000/1200" + let portraitUrlString = "https://picsum.photos/1000/1200" + let landscapeUrlString = "https://picsum.photos/2000/1000" + let urlString = Int.random(in: 0...1) == 0 ? portraitUrlString : landscapeUrlString guard let url = URL(string: urlString), let (data, _) = try? await URLSession.shared.data(from: url), let image = UIImage(data: data) diff --git a/Sources/SwiftyCrop/Models/CropViewModel.swift b/Sources/SwiftyCrop/Models/CropViewModel.swift index 9d5e16d..869d4f8 100644 --- a/Sources/SwiftyCrop/Models/CropViewModel.swift +++ b/Sources/SwiftyCrop/Models/CropViewModel.swift @@ -3,8 +3,12 @@ import UIKit class CropViewModel: ObservableObject { private let maxMagnificationScale: CGFloat - var imageSizeInView: CGSize = .zero - var maskRadius: CGFloat + var imageSizeInView: CGSize = .zero { + didSet { + maskRadius = min(maskRadius, min(imageSizeInView.width, imageSizeInView.height) / 2) + } + } + @Published var maskRadius: CGFloat @Published var scale: CGFloat = 1.0 @Published var lastScale: CGFloat = 1.0