Skip to Content
iOS 10 Swift Programming Cookbook
book

iOS 10 Swift Programming Cookbook

by Vandad Nahavandipoor
December 2016
Intermediate to advanced content levelIntermediate to advanced
456 pages
8h 46m
English
O'Reilly Media, Inc.
Content preview from iOS 10 Swift Programming Cookbook

Chapter 17. UI Dynamics

UI Dynamics allow you to create very nice effects on your UI components, such as gravity and collision detection. Let’s say that you have two buttons on the screen that the user can move around. You could create opposing gravity fields on them so that they repel each other and cannot be dragged into each other. Or, for instance, you could provide a more dynamic UI by creating a turbulence field under all your UI components so that they move around automatically ever so slightly (or through a noise field, as described in Recipe 17.4) even when the user is not interacting with them. All of this is possible with the tools that Apple has given you in UIKit. You don’t have to use any other framework to dig into UI Dynamics.

One of the basic concepts in UI Dynamics is an animator. Animator objects, which are of type UIDynamicAnimator, hold every other effect together and orchestrate all the effects. For instance, if you have collision detection and gravity effects, the animator decides how the pull on an object through gravity will work hand in hand with the collision detection around the edges of your reference view.

Reference views are like canvases where all your animations happen. Effects are added to views and then added to an animator, which itself is placed on a reference view. In other words, the reference view is the canvas and the views on your UI (buttons, lables, etc.) will have effects.

17.1 Adding a Radial Gravity Field to Your UI

Problem

You ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

iOS 11 Swift Programming Cookbook

iOS 11 Swift Programming Cookbook

Vandad Nahavandipoor
iOS 7 Programming Cookbook

iOS 7 Programming Cookbook

Vandad Nahavandipoor

Publisher Resources

ISBN: 9781491966426Errata PageSupplemental Content