Mobile App Development 2021W Lecture 9
Video
Video from the lecture given on February 8, 2021 is now available.
Code
import SwiftUI
struct ContentView: View {
@State var c = 0
@State var p = CGPoint(x: 0, y: 0)
var body: some View {
VStack{
Text("Hello, you clicked \(c) times.")
.padding()
Image("sadDog")
.resizable()
.scaledToFit()
.position(p)
.gesture(
DragGesture()
.onEnded {_ in
print("Drag ended!")
self.p = CGPoint(x: 0, y: 0)
}
.onChanged {v in
self.p = v.location
}
)
.onTapGesture(count: 1, perform: {
c = c + 1
})
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}