mirror of
https://github.com/laosb/CropImage.git
synced 2025-04-30 23:51:08 +00:00
fix: iOS 14 compatibility.
This commit is contained in:
parent
9ff52995b7
commit
b42b532ddb
1 changed files with 57 additions and 41 deletions
|
@ -16,54 +16,70 @@ public struct DefaultControlsView: View {
|
||||||
@Binding var rotation: Angle
|
@Binding var rotation: Angle
|
||||||
var crop: () async -> Void
|
var crop: () async -> Void
|
||||||
|
|
||||||
|
var rotateButton: some View {
|
||||||
|
Button {
|
||||||
|
let roundedAngle = Angle.degrees((rotation.degrees / 90).rounded() * 90)
|
||||||
|
withAnimation {
|
||||||
|
rotation = roundedAngle + .degrees(90)
|
||||||
|
}
|
||||||
|
} label: {
|
||||||
|
Label("Rotate", systemImage: "rotate.right")
|
||||||
|
.font(.title2)
|
||||||
|
.foregroundColor(.accentColor)
|
||||||
|
.labelStyle(.iconOnly)
|
||||||
|
.padding(.horizontal, 6)
|
||||||
|
.padding(.vertical, 3)
|
||||||
|
.background(
|
||||||
|
RoundedRectangle(cornerRadius: 5, style: .continuous)
|
||||||
|
.fill(.background)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
.buttonStyle(.plain)
|
||||||
|
.padding()
|
||||||
|
}
|
||||||
|
|
||||||
|
var resetButton: some View {
|
||||||
|
Button("Reset") {
|
||||||
|
withAnimation {
|
||||||
|
offset = .zero
|
||||||
|
scale = 1
|
||||||
|
rotation = .zero
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var cropButton: some View {
|
||||||
|
Button { Task {
|
||||||
|
await crop()
|
||||||
|
} } label: {
|
||||||
|
Label("Crop", systemImage: "checkmark.circle.fill")
|
||||||
|
.font(.title2)
|
||||||
|
.foregroundColor(.accentColor)
|
||||||
|
.labelStyle(.iconOnly)
|
||||||
|
.padding(1)
|
||||||
|
.background(
|
||||||
|
Circle().fill(.background)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
.buttonStyle(.plain)
|
||||||
|
.padding()
|
||||||
|
}
|
||||||
|
|
||||||
public var body: some View {
|
public var body: some View {
|
||||||
VStack {
|
VStack {
|
||||||
Spacer()
|
Spacer()
|
||||||
HStack {
|
HStack {
|
||||||
Button {
|
rotateButton
|
||||||
let roundedAngle = Angle.degrees((rotation.degrees / 90).rounded() * 90)
|
|
||||||
withAnimation {
|
|
||||||
rotation = roundedAngle + .degrees(90)
|
|
||||||
}
|
|
||||||
} label: {
|
|
||||||
Label("Rotate", systemImage: "rotate.right")
|
|
||||||
.font(.title2)
|
|
||||||
.foregroundColor(.accentColor)
|
|
||||||
.labelStyle(.iconOnly)
|
|
||||||
.padding(.horizontal, 6)
|
|
||||||
.padding(.vertical, 3)
|
|
||||||
.background(
|
|
||||||
RoundedRectangle(cornerRadius: 5, style: .continuous)
|
|
||||||
.fill(.background)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
.buttonStyle(.plain)
|
|
||||||
.padding()
|
|
||||||
Spacer()
|
Spacer()
|
||||||
Button("Reset") {
|
if #available(iOS 15.0, macOS 13.0, *) {
|
||||||
withAnimation {
|
resetButton
|
||||||
offset = .zero
|
.buttonStyle(.bordered)
|
||||||
scale = 1
|
.buttonBorderShape(.roundedRectangle)
|
||||||
rotation = .zero
|
} else {
|
||||||
}
|
resetButton
|
||||||
}
|
}
|
||||||
.buttonStyle(.bordered)
|
|
||||||
.buttonBorderShape(.roundedRectangle)
|
|
||||||
Spacer()
|
Spacer()
|
||||||
Button { Task {
|
cropButton
|
||||||
await crop()
|
|
||||||
} } label: {
|
|
||||||
Label("Crop", systemImage: "checkmark.circle.fill")
|
|
||||||
.font(.title2)
|
|
||||||
.foregroundColor(.accentColor)
|
|
||||||
.labelStyle(.iconOnly)
|
|
||||||
.padding(1)
|
|
||||||
.background(
|
|
||||||
Circle().fill(.background)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
.buttonStyle(.plain)
|
|
||||||
.padding()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue