diff --git a/Demo/SwiftyCropDemo/ContentView.swift b/Demo/SwiftyCropDemo/ContentView.swift index f4081a2..08b1060 100644 --- a/Demo/SwiftyCropDemo/ContentView.swift +++ b/Demo/SwiftyCropDemo/ContentView.swift @@ -9,6 +9,7 @@ struct ContentView: View { @State private var rotateImage: Bool @State private var maxMagnificationScale: CGFloat @State private var maskRadius: CGFloat + @State private var zoomSensitivity: CGFloat @FocusState private var textFieldFocused: Bool init() { @@ -17,6 +18,7 @@ struct ContentView: View { _rotateImage = State(initialValue: defaultConfiguration.rotateImage) _maxMagnificationScale = State(initialValue: defaultConfiguration.maxMagnificationScale) _maskRadius = State(initialValue: defaultConfiguration.maskRadius) + _zoomSensitivity = State(initialValue: defaultConfiguration.zoomSensitivity) } var body: some View { @@ -91,6 +93,15 @@ struct ContentView: View { DecimalTextField(value: $maskRadius) .focused($textFieldFocused) } + + HStack { + Text("Zoom sensitivity") + + .frame(maxWidth: .infinity, alignment: .leading) + + DecimalTextField(value: $zoomSensitivity) + .focused($textFieldFocused) + } } } .toolbar { @@ -117,7 +128,8 @@ struct ContentView: View { maxMagnificationScale: maxMagnificationScale, maskRadius: maskRadius, cropImageCircular: cropImageCircular, - rotateImage: rotateImage + rotateImage: rotateImage, + zoomSensitivity: zoomSensitivity ) ) { croppedImage in // Do something with the returned, cropped image diff --git a/README.md b/README.md index a15102c..167e588 100644 --- a/README.md +++ b/README.md @@ -144,6 +144,7 @@ You can also configure `SwiftyCropView` by passing a `SwiftyCropConfiguration`. | `maskRadius` | `CGFloat`: The radius of the mask used for cropping. Defaults to `130`. A good way is to make it dependend on the screens size. | | `cropImageCircular` | `Bool`: When using the cropping mask `circle`, whether the resulting image should also be masked as circle. Defaults to `false`. | | `rotateImage` | `Bool`: Whether the image can be rotated when cropping using pinch gestures. Defaults to `true`. | +| `zoomSensitivity` | `CGFloat`: Zoom sensitivity when cropping. Increase to make zoom faster / less sensitive. Defaults to `1.0`. | Create a configuration like this: ```swift @@ -151,7 +152,8 @@ let configuration = SwiftyCropConfiguration( maxMagnificationScale = 4.0, maskRadius: 130, cropImageCircular: false, - rotateImage: true + rotateImage: true, + zoomSensitivity = 1.0 ) ``` and use it like this: diff --git a/Sources/SwiftyCrop/Models/SwiftyCropConfiguration.swift b/Sources/SwiftyCrop/Models/SwiftyCropConfiguration.swift index 8cda96c..3a3e06a 100644 --- a/Sources/SwiftyCrop/Models/SwiftyCropConfiguration.swift +++ b/Sources/SwiftyCrop/Models/SwiftyCropConfiguration.swift @@ -6,6 +6,7 @@ public struct SwiftyCropConfiguration { public let maskRadius: CGFloat public let cropImageCircular: Bool public let rotateImage: Bool + public let zoomSensitivity: CGFloat /// Creates a new instance of `SwiftyCropConfiguration`. /// @@ -18,15 +19,18 @@ public struct SwiftyCropConfiguration { /// Defaults to `false`. /// - rotateImage: Option to rotate image. /// Defaults to `true`. + /// - zoomSensitivity: Sensitivity when zooming. Default is `1.0`. Decrease to increase sensitivity. public init( maxMagnificationScale: CGFloat = 4.0, maskRadius: CGFloat = 130, cropImageCircular: Bool = false, - rotateImage: Bool = true + rotateImage: Bool = true, + zoomSensitivity: CGFloat = 1 ) { self.maxMagnificationScale = maxMagnificationScale self.maskRadius = maskRadius self.cropImageCircular = cropImageCircular self.rotateImage = rotateImage + self.zoomSensitivity = zoomSensitivity } } diff --git a/Sources/SwiftyCrop/View/CropView.swift b/Sources/SwiftyCrop/View/CropView.swift index a61aa47..b8ca961 100644 --- a/Sources/SwiftyCrop/View/CropView.swift +++ b/Sources/SwiftyCrop/View/CropView.swift @@ -32,7 +32,7 @@ struct CropView: View { var body: some View { let magnificationGesture = MagnificationGesture() .onChanged { value in - let sensitivity: CGFloat = 0.2 + let sensitivity: CGFloat = 0.1 * configuration.zoomSensitivity let scaledValue = (value.magnitude - 1) * sensitivity + 1 let maxScaleValues = viewModel.calculateMagnificationGestureMaxValues()