-
Notifications
You must be signed in to change notification settings - Fork 3
/
ContentView.swift
50 lines (42 loc) · 1.39 KB
/
ContentView.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//
// ContentView.swift
// P17D Flashzilla
//
// Created by Julian Moorhouse on 06/05/2021.
//
import SwiftUI
struct ContentView: View {
// How far the cirlce has been dragged
@State private var offset = CGSize.zero
@State private var isDragging = false
var body: some View {
let dragGesture = DragGesture()
.onChanged { value in self.offset = value.translation }
.onEnded { _ in
withAnimation {
self.offset = .zero
self.isDragging = false
}
}
let pressGesture = LongPressGesture()
.onEnded { value in
withAnimation {
self.isDragging = true
}
}
// Combine these gestures which will force the user to long press then drag
let combined = pressGesture.sequenced(before: dragGesture)
// a 64x64 circle that scales up when it's dragged, sets its offset to whatever we had back from the drag gesture, and uses our combined gesture
return Circle()
.fill(Color.red)
.frame(width: 64, height: 64)
.scaleEffect(isDragging ? 1.5 : 1)
.offset(offset)
.gesture(combined)
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}