UI layout issues on iOS playground

I have a UIViewController subclass that I made in a regular app, and I tried moving it over to my playground, but there are some layout issues happening in the playground that weren't in the regular app (and there were no Auto Layout-related messages in the console when running the app). I've got a UIStackView pinned to the bottom of the view controller's view (meaning the UIView at the highest level of the view hierarchy), and that seems to be where most of the issues are happening.


In the playground, the live view is set to an instance of my UIViewController subclass. I'm also seeing different (but both incorrect) results when running the playground on my Mac vs. in the Swift Playgrounds app. When running on the Mac in Xcode, the live view looks more like the size of an iPhone, but the size reported by the view controller instance's view's bounds is 768x1024, which is an iPad screen size.


All of this UI setup is done in code - no Interface Builder files involved since I've had so many issues with external files in playgrounds.


Any suggestions on how to fix this and/or if this is a common issue?

Replies

Are you using a .playground or a .playgroundbook file? I know that for playground books (iPad-only), you can specify LiveViewEdgeToEdge, which will make it fill the entirety of the visible space. If that's what you're looking for, I recommend checking this out: https://developer.apple.com/documentation/swift_playgrounds/structuring_content_for_swift_playgrounds/adding_a_page_to_a_playground_book

It’s a .playground file

And also, the actual app that I tested wtih even works (mostly) fine on an iPhone simulator - so the fact that the viewable area of a playground on an iPad is smaller than the iPad's screen doesn't seem to make a difference (I'm running it on a 9.7" iPad)

And if it isn't clear from other posts in this thread, all of my UI layout is set up with Auto Layout - many things are pinned to the top/bottom/left/right anchors