Closed QuaRang1225 closed 2 months ago
GeometryReader{ geo in
let g = geo.frame(in: .named("G"))
PhotosItemView(assets: selectedAssets)
.scaledToFit()
.frame(maxWidth: .infinity,maxHeight: .infinity)
.matchedGeometryEffect(id: selectedAssets.localIdentifier, in: namespace)
.onChange(of: changed) { change in
withAnimation(.easeIn(duration: 0.1)){
if g.minX > 0{
currentOffset.width = currentOffset.width - g.minX
}
if g.minY > 0{
currentOffset.height = currentOffset.height - g.minY
if mainCurrentScale == 1{
self.selectedAssets = nil
}
}
if g.maxX < width(){
currentOffset.width = g.minX - currentOffset.width
}
if g.maxY < width(){
currentOffset.height = g.minY - currentOffset.height
}
if !change{
endOffset = currentOffset
}
}
}
}
.scaleEffect(mainCurrentScale)
.offset(currentOffset)
.frame(height: height()/1.3)
.simultaneousGesture(drag)
.simultaneousGesture(pinch)
.onTapGesture(count: 2) {
withAnimation {
if mainCurrentScale == 1{
mainCurrentScale = 2
endScale = 2
}else{
mainCurrentScale = 1
endScale = 1
currentOffset = .zero
endOffset = .zero
}
}
}
.coordinateSpace(name: "G")
var drag:some Gesture{
DragGesture()
.updating($changed){ _,changed,_ in
changed = true
}
.onChanged{ gesture in
currentOffset = endOffset + gesture.translation
}
}
var pinch:some Gesture{
MagnificationGesture()
.updating($changed){ _,changed,_ in
changed = true
}
.onChanged { gesture in
mainCurrentScale = min(max(gesture + endScale - 1, 1), 3)
}
.onEnded { gesture in
withAnimation(.easeIn(duration: 0.1)){
endScale = min(max(endScale + gesture - 1, 1), 3)
if endScale < 1 {
mainCurrentScale = 1
endScale = 1
currentOffset = .zero
endOffset = .zero
}
}
}
}
이미지 드래그,더블 터치,핀치 인&아웃 제스쳐 추가