Hello I’m engaged on a iOS model of a mission I did for Android and I’m attempting to position markers/annotations on a picture. I used to be capable of get some assist for the android model however I do not actually perceive the mathematics and the best way to do the identical in SwiftUI.
Proper now that is what I’ve setup in Swift –
import SwiftUI
import Kingfisher
struct ImageView: View {
@StateObject var viewModel = viewModel()
let index: Int
@State var showSheet: Bool = false
@State var present: Bool = false
@State var currentAnnotationSelected: SelectedAnnotationModel?
@State var showDialog: Bool = false
@State var observe: String = ""
@State var localY: CGFloat = 0
@State var globalY: CGFloat = 0
@State var localX: CGFloat = 0
@State var globalX: CGFloat = 0
var annotationIndex: Int = 0
var physique: some View {
VStack {
KFImage.url(URL(string: viewModel.uri ?? ""))
.placeholder {ProgressView()}
.loadDiskFileSynchronously()
.cacheMemoryOnly()
.gesture(DragGesture(minimumDistance: 0, coordinateSpace: .native).onEnded { dragGesture in
self.localY = dragGesture.location.y
self.localX = dragGesture.location.x
showSheet = true
})
}
.sheet(isPresented: $showSheet) {
VStack {
AnnotationNote(x: Int(self.localX), y: Int(self.localY))
}
.presentationDetents([.medium])
.presentationDragIndicator(.seen)
}
.overlay {
VStack{
if(viewModel.annotations != [] && viewModel.annotations != nil) {
ForEach(Array((viewModel.annotations.enumerated())!), id: .offset) { index, annotation in
Circle()
.body(width: 15, peak: 15)
.place(x: 100, y: 100)
//.place(x: CGFloat(annotation.coordinateX), y: CGFloat(annotation.coordinateY))
.onTapGesture {
currentAnnotationSelected = SelectedAnnotationModel(index: index, particulars: annotation)
self.showSheet = true
}
}
}
}
}
}
}
It is giving me 2 points although – 1. The markers usually are not displaying the place I clicked and a couple of. I want the android and iOS variations to each present the markers accurately for a similar picture on any gadget, so I am undecided the best way to do those self same calculations in swift? – Android Model