Positioning views: is it me or SwiftUI ?

After more than 2 years of intense use of SwiftUI I appreciate many of its features, particularly the speed at which I can get some code running.

But, there are some major buts …

  • Screen Position,

I keep struggling with try, test, error and retry to position views relative to each others, withy many iterations to tune the x and y parameters. And preview does not help when view is too complex: I find it more reliable to test in simulator.

At the end, my code is messed with .position, .offset, … that I manually adjusted but may break if I change something elsewhere in the body. The fact that position is relative to center of view (different from UIKit) makes it even more mind boggling.

For sure, UIKit constraints were not so easy, but you got a very stable code. That's not the case with SwiftUI

  • z position

In some cases, I want the View to appear on front of all others.

It may be a very simple Rectangle() with overlay, e.g., to mimic an alert.

And I struggle with the Rectangle drawn behind another view, even trying to adjust the zIndex to no avail…

Should I create an explicit View instead of creating the Rectangle directly in the body ?

So am I misusing SwiftUI, or are they points that SwiftUI should improve in the future ?

Answered by Claude31 in 764822022

A very partial answer: to keep views at fixed relative positions, embed in HStack or VStack.

I close the thread even though I did not get answer.

Accepted Answer

A very partial answer: to keep views at fixed relative positions, embed in HStack or VStack.

I close the thread even though I did not get answer.

Positioning views: is it me or SwiftUI ?
 
 
Q