The SwiftUI Field Guidebeta

Offset

The offset modifier lets us change where a view is drawn without modifying the surrounding layout. As far as the view's parent is concerned, the view is still in its original position (we can see this by enabling the yellow border).

Code
HStack {    Color.green    Color.red        .offset(x: 
, y:
)
/* .border(Color.yellow) */ Color.blue}
Preview

Because the offset modifier doesn't affect the frame, it's especially useful during animations and other effects. For example, if we use an alignment guide to move the red view above, the frame of the stack also changes:

Code
HStack {    Color.green    Color.red        .alignmentGuide(            VerticalAlignment.center        ) { dim in (dim.height / 2) - 
}
Color.blue}
Preview