The UI system in WatchKit is entirely linear. As you’ve seen thus far, when you add interface objects to an interface controller, they stack from top to bottom. Instead of using Auto Layout to position user interface objects with constraints, or the old “springs and struts” style of autoresizing masks that came before it, WatchKit handles positioning interface objects on your behalf. You probably noticed this behavior when you were adding interface objects to your storyboard.
This system of automatically positioning elements in a sequence is much more like the new UIStackView class in iOS than the other, older iOS layout paradigms. Introduced in iOS 9, UIStackView class is a container for other UIView objects. Instead of using Auto Layout constraints to position its subviews, UIStackView places them along a linear path, much like the layout system in WatchKit. Its announcement at the Apple Worldwide Developers Conference (WWDC) 2015 was met with great enthusiasm from iOS developers who had long wanted an easier approach to interface layout.
In fact, WatchKit’s UI system predates UIStackView by about six months. You can adjust their relative positioning in your storyboard, but sometimes you’ll want more control over your layout. That’s where groups come in. The WKInterfaceGroup interface object acts as a container for other objects, letting you adjust the positioning and size of elements in more precise ways. You can set background colors and images for groups, hide them from your UI, animate their properties, and even nest groups together. In this chapter, you’ll discover the capabilities of groups, which make interesting user interfaces possible.
18.118.200.95