Skip to content

Instantly share code, notes, and snippets.

@diemer
Last active September 6, 2022 21:18
Show Gist options
  • Select an option

  • Save diemer/725ea4437df61cc65975a229d5085788 to your computer and use it in GitHub Desktop.

Select an option

Save diemer/725ea4437df61cc65975a229d5085788 to your computer and use it in GitHub Desktop.
Simple SwiftUI In App Tour sketch
import SwiftUI
struct ContentView: View {
@State var infoIndex: Int = 0
typealias TourPOI = (point: UnitPoint, radii: (start: CGFloat, end: CGFloat))
var infos: [TourPOI] = [
// UnitPoint is a value between 0 and 1,
// x represents the percentage of width,
// y represents the percentage of height
(point: .init(x: 0.75, y: 0.05), radii: (start: 0, end: 90)),
(point: .init(x: 0.25, y: 0.25), radii: (start: 0, end: 90)),
(point: .init(x: 0.5, y: 0.5), radii: (start: 100.0, end: 120.0))
]
var body: some View {
let selectedInfo = infos[infoIndex]
GeometryReader { proxy in
ZStack {
Rectangle()
.fill(.blue)
ForEach(Array(infos.enumerated()), id: \.0) {
Text("Step \($0 + 1)")
.position(x: $1.point.x * proxy.size.width, y: $1.point.y * proxy.size.height)
}
Rectangle()
.fill(.black.opacity(0.5))
.mask(RadialGradient(colors: [.clear,.clear, .black], center: selectedInfo.point, startRadius: selectedInfo.radii.start, endRadius: selectedInfo.radii.end))
.onTapGesture {
withAnimation {
incrementInfo()
}
}
}
}
}
func incrementInfo() {
guard infos.count != infoIndex + 1 else {
infoIndex = 0
return
}
infoIndex += 1
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment