Last updated 2 years ago
Applying .position() will change view's frame and become a "push-out" view. ๐ Paul
absolute position in its parentโs coordinate space.
will change frame and become a "push-out" view.
relative to its original position.
won't change frame.
import SwiftUI struct PositionView: View { let text = Text("Hello SwiftUI") var body: some View { HStack { Group { // 1. original text text // โญ๏ธ 2. offset: frame unchanged // (โญ๏ธ so is background) text.offset(x: 0, y: 50) // โญ๏ธ 3. if you want to move background too, // have to apply .background() first. text .background(.indigo) .offset(x: 0, y: 50) // โญ๏ธ 4. position: frame changedโ๏ธ text.position(x: 0, y: 50) } .padding(.horizontal, 6) .background(.pink) .frame(width: 150, height: 150) .border(.white(0.4)) } } }
SwiftOnTap โฉ View โฉ .position(_:)
SwiftUI โฉ View Layout and Presentation
Making Fine Adjustments to a View's Position
offset(x:y:)
position(x:y:)
Paul โฉ Absolute positioning for SwiftUI views โญ๏ธ differences between .position & .offset
Point