NEW: My new book Pro SwiftUI is out now – level up your SwiftUI skills today! >>

Problem with "Hacking With macOS" Swift version - Project 6: Animation

Forums > Books

This may be a problem with my using a beta OS... I'm running MacOS Montery 12.5 beta (21G5056b) and Xcode Version 13.4.1 (13F100).

I've not been comprehensive in my attempt to debug this, but I have located a very simple example of the problem.

I create an Xcode project for AnimationSandbox and add the first set of code from the tutorial

Text("Click Me")
    .onTapGesture {
        // do nothing just yet
    }
    .padding(50)
    .background(.red)
    .foregroundColor(.white)
    .clipShape(Circle())
    .padding(100)

This works correctly in the preview - like the illustration in the tutorial - but when built and run, the text is missing. That is, I get a red circle with no text.

The problem appears to be caused by the .padding(100); if I comment this out

Text("Click me")
            .onTapGesture {
                    // do nothing just yet
                }
            .padding(50)
            .background(.red)
            .foregroundColor(.white)
            .clipShape(Circle())
            //.padding(100)

the preview and app match (what I take to be) correctly.

OK - the problem is that if the window size of the app is too small, the text doesn't appear. If I resize the window it works correctly.

Unfortunately it's taken me a couple of hours to understand this.

   

Hacking with Swift is sponsored by Play

SPONSORED Play is the first native iOS design tool created for designers and engineers. You can install Play for iOS and iPad today and sign up to check out the Beta of our macOS app with SwiftUI code export. We're also hiring engineers!

Click to learn more about Play!

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

Reply to this topic…

You need to create an account or log in to reply.

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.