Is there any way to move a group of views within another without grouping all in the center?
Edit: Here some images with the process.
1.- I have a view with separate subviews (labels, buttons, images...)
2.- I create a new view (that will contain all the subviews)
3.- Select all the subviews and put them in the new super view.
4.- When the subviews are in the new "super"view, all of them are centered and I need to relocate all.
That's the simplest use case you can think of. In SwiftUI we organize all our UI using those 3 stacks. We also use Group , a view that, similarly to stacks, can be used to group together multiple views, but contrary to stack views, it does not affect layout. VStack { Group { Text("Hello World") Text("Hello again!") } }
Auto Layout constraints allow us to create views that dynamically adjust to different size classes and positions. The constraints will make sure that your views adjust to any size changes without having to manually update frames or positions.
I found a very nifty solution that you are not gonna believe .. !
I had a group of like 30 labels and buttons positioned pixel by pixel, so I HAD to, no matter what, move them while preserving their relative locations to each other.. Here is what I did:
I haven't read this anywhere, I came up with it yesterday .. Am 100% sure people somewhere have found this way before me, though.
EDIT:
It seems Xcode 4.5 renders this answer obsolete. Copy/Pasting a bunch of views now retains their relative locations to each other. Don't bother with this if you grew a habit on using it!
Actually, I think this answer is still viable!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With