summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFuwn <[email protected]>2025-02-25 00:21:20 -0800
committerFuwn <[email protected]>2025-02-25 00:21:20 -0800
commit09a7a6aaa5203bb85add568c5c5e171f0a97de46 (patch)
tree1c29554d663b8a60f7f0bf21eae7588fb503e0f9
parentfeat: Development commit (diff)
downloadsora-testing-09a7a6aaa5203bb85add568c5c5e171f0a97de46.tar.xz
sora-testing-09a7a6aaa5203bb85add568c5c5e171f0a97de46.zip
feat: Development commit
-rw-r--r--Sora/Views/InteractiveImageView.swift102
1 files changed, 51 insertions, 51 deletions
diff --git a/Sora/Views/InteractiveImageView.swift b/Sora/Views/InteractiveImageView.swift
index 41d26d3..39e6c83 100644
--- a/Sora/Views/InteractiveImageView.swift
+++ b/Sora/Views/InteractiveImageView.swift
@@ -11,65 +11,65 @@ struct InteractiveImageView: View {
@State private var zoomAnchor: UnitPoint = .center
var body: some View {
- GeometryReader { geometry in
- VStack {
- image
- .resizable()
- .scaledToFit()
- .scaleEffect(currentScale, anchor: zoomAnchor)
- .offset(currentOffset)
- .frame(width: screenWidth, height: screenHeight)
- .clipped()
- .gesture(
- MagnifyGesture()
+ image
+ .resizable()
+ .scaledToFit()
+ .scaleEffect(currentScale, anchor: zoomAnchor)
+ .offset(currentOffset)
+ .clipped()
+ .background(
+ GeometryReader { geometry in
+ Color.clear
+ .onAppear {
+ screenWidth = geometry.size.width
+ screenHeight = geometry.size.height
+ }
+ }
+ )
+ .gesture(
+ MagnifyGesture()
+ .onChanged { gesture in
+ withAnimation(.interactiveSpring()) {
+ if previousScale == 1 {
+ zoomAnchor = gesture.startAnchor
+ }
+
+ currentScale = max(previousScale * gesture.magnification, 1)
+ }
+ }
+ .onEnded { _ in
+ previousScale = currentScale
+ }
+ .simultaneously(
+ with: DragGesture(minimumDistance: 0)
.onChanged { gesture in
withAnimation(.interactiveSpring()) {
- if previousScale == 1 {
- zoomAnchor = gesture.startAnchor
- }
+ var newOffset: CGSize = .zero
+ let offset = gesture.translation
+
+ newOffset.width = offset.width + previousOffset.width
+ newOffset.height = offset.height + previousOffset.height
- currentScale = max(previousScale * gesture.magnification, 1)
+ currentOffset = clampOffset(offset: newOffset)
}
}
.onEnded { _ in
- previousScale = currentScale
+ previousOffset = currentOffset
}
- .simultaneously(
- with: DragGesture(minimumDistance: 0)
- .onChanged { gesture in
- withAnimation(.interactiveSpring()) {
- var newOffset: CGSize = .zero
- let offset = gesture.translation
-
- newOffset.width = offset.width + previousOffset.width
- newOffset.height = offset.height + previousOffset.height
-
- currentOffset = clampOffset(offset: newOffset)
- }
- }
- .onEnded { _ in
- previousOffset = currentOffset
- }
- )
)
- .highPriorityGesture(
- TapGesture(count: 2)
- .onEnded {
- withAnimation {
- currentScale = 1
- previousScale = 1
- currentOffset = .zero
- previousOffset = .zero
- zoomAnchor = .center
- }
- }
- )
- }
- .onAppear {
- screenWidth = geometry.size.width
- screenHeight = geometry.size.height
- }
- }
+ )
+ .highPriorityGesture(
+ TapGesture(count: 2)
+ .onEnded {
+ withAnimation {
+ currentScale = 1
+ previousScale = 1
+ currentOffset = .zero
+ previousOffset = .zero
+ zoomAnchor = .center
+ }
+ }
+ )
}
private func clampOffset(offset: CGSize = .zero) -> CGSize {