Chapter 6. The User Interface

UIKit is the main framework for working with various UI components on iOS. You can use other frameworks, such as OpenGL, to build your own UI the way you want, without being constrained by UIKit, but almost all developers use UIKit at some stage in their applications to bring intuitive user interfaces to their apps. One of the main reasons for this is that UIKit by default takes advantage of all the latest technologies in iOS and is kept up to date. For instance, many years back when Apple started producing Retina displays for iOS devices, all apps that were using UIKit could take advantage of the much sharper resolution afforded by Retina displays without requiring an update to their UIKit components. Applications that were using other technologies for rendering text had to update their apps to conform with Retina displays.

In this chapter, we will have a look at some of the most interesting features of UIKit and playgrounds.

6.1 Animating Views

Problem

You have an instance of UIView and you would like to apply various animations to it, such as changing its background color inside an animation block.

Solution

Use the UIViewPropertyAnimator class and specify the properties of your views that you would like to animate, including their new values. For instance, you can instantiate UIViewPropertyAnimator and set a delay and an animation length, and then change the background color of your view instances inside the animation block of your UIViewPropertyAnimator ...

Get iOS 10 Swift Programming Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.