Chapter 8. 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.

8.1 Animating Details with Peek and Pop

Problem

You want to provide your users the ability to see details of content that you have placed on the screen, through the use of 3D Touch on their iOS devices.

Solution

Follow these steps:

  1. Ask your view controller’s traitCollection.forceTouchCapability property whether 3D Touch capabilities are available on the host device by comparing its value to available.
  2. If 3D Touch is available, call the registerForPreviewing(with:sourceView:) method of your view controller to register your ...

Get iOS 11 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.