Mobile App Development 2021W Lecture 9

From Soma-notes
Revision as of 14:39, 8 February 2021 by Soma (talk | contribs) (Created page with "==Video== Video from the lecture given on February 8, 2021 [https://homeostasis.scs.carleton.ca/~soma/mad-2021w/lectures/comp1601-2021w-lec09-20210208.m4v is now available]....")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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()
    }
}