Introduction
Iterating Over Your Solution
Apple is constantly improving SwiftUI. With every release cycle, Apple engineers introduce new native views and APIs that allow developers to achieve even more with SwiftUI. And with new Views, you get more power and flexibility to build your own custom views.
In the last lesson, you wrote code so that RGB Picker can support landscape orientation. You solved the issue of the layout being out of bounds by re-arranging the views to better occupy the available space. No matter what orientation the user wants to use their device, the app is looking great.
But, there’s still room for improvement. The current solution is switching between two different views, depending on the orientation of the device. But with the latest SwiftUI APIs, you can change the layout of the container with even less code, while still allowing for animations to work and reusing the same code.
This isn’t the best solution, given the new APIs. But don’t worry, iterating over the code and gradually improving it, just like Apple, is part of the process :]
At the end of this lesson, you’ll have learned:
- How different layout containers behave when switching axes and how SwiftUI animates that.
- AnyLayout and how it can switch between layouts and even animate that change.
- How to use ViewThatFits to automatically choose between different views of different sizes.
Additionally, you’ll keep practicing refactoring code to create smaller and reusable views to remove code duplication.