UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Day 94: Layout and Geometry challenge #2 (Word Scramble)

Forums > 100 Days of SwiftUI

I'm having real trouble with this one. I've managed to do it successfully using .global but I'd like to be able to define a custom coordinateSpace in order to directly read the number of pixels from the top of the list instead. I've tried putting coordinateSpace after multiple views (see below). Every single one except for the geometry coordinate space is identical to .global and the geometry space is identical to .local – can anyone tell me what I'm doing wrong?

TextField("Enter your word", text: $newWord, onCommit: addNewWord)
    .textFieldStyle(RoundedBorderTextFieldStyle())
    .autocapitalization(.none)
    .padding()
    .coordinateSpace(name: "textfield")

List(usedWords, id: \.self) { word in
    GeometryReader { geo in
        HStack {
            Image(systemName: "\(word.count).circle")
            Text(word)
            Text("\(geo.frame(in: .global).midY, specifier: "%.0f") \(geo.frame(in: .named("list")).midY, specifier: "%.0f") \(geo.frame(in: .named("geometry")).midY, specifier: "%.0f") \(geo.frame(in: .named("textfield")).midY, specifier: "%.0f")")
        }
        .accessibilityElement(children: .ignore)
        .accessibility(label: Text("\(word), \(word.count) letters"))
        .offset(x: wordOffset(for: geo.frame(in: .global).midY), y: 0.0)
    }
    .coordinateSpace(name: "geometry")
}
.coordinateSpace(name: "list")

3      

BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS.

Get it on Hacking with Swift+

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.