51 lines
1.6 KiB
Swift
51 lines
1.6 KiB
Swift
//
|
|
// CompanyGalleryORView.swift
|
|
// IOS_study
|
|
//
|
|
// Created by CC-star on 2025/7/22.
|
|
//
|
|
|
|
import SwiftUI
|
|
import Kingfisher
|
|
|
|
struct CompanyGalleryORView: View {
|
|
let imageURLStrs: [String]
|
|
@Environment(\.dismiss) var dismiss
|
|
@State var currentPage: Int
|
|
@State var dragOffset: CGSize = .zero
|
|
var body: some View {
|
|
TabView(selection: $currentPage) {
|
|
ForEach(imageURLStrs.indices, id: \.self) { i in
|
|
VStack {
|
|
KFImage(URL(string: imageURLStrs[i]))
|
|
.placeholder { ProgressView() }.loadDiskFileSynchronously().fade(duration: 0.15)
|
|
.resizable().scaledToFit().tag(i)
|
|
.offset(y: dragOffset.height)
|
|
}.frame(maxWidth: .infinity, maxHeight: .infinity).pinchToZoom()
|
|
}
|
|
}.bg().tabViewStyle(.page)
|
|
.toolbarVisibility(.hidden, for: .tabBar)
|
|
.toolbar {
|
|
ToolbarItem(placement: .principal) {
|
|
Text("\(currentPage + 1)/\(imageURLStrs.count)").tc().bold()
|
|
}
|
|
}
|
|
.gesture(//手势【拖拽】
|
|
DragGesture()
|
|
.onChanged({ gesture in
|
|
if gesture.translation.height > 0 {
|
|
dragOffset = gesture.translation
|
|
}
|
|
})
|
|
.onEnded { gesture in
|
|
if gesture.translation.height > 80 {//垂直偏移80 -> 返回上一页
|
|
dismiss()
|
|
} else {
|
|
withAnimation { dragOffset = .zero }
|
|
}
|
|
}
|
|
)
|
|
}
|
|
}
|
|
|