In this article

Introduction to iOS 7

03/19/2017

7 minutes to read

Contributors

In this article

This article covers the major new APIs introduced in iOS 7, including View Controller transitions, enhancements to UIView animations, UIKit Dynamics and Text Kit. It also covers some of the changes to the user interface, and the new enchanced multitasking capabilities.

iOS 7 is a major update to iOS. It introduces a completely new user interface design that puts focus on content rather than application chrome. Alongside the visual changes, iOS 7 adds a plethora of new APIs to create richer interactions and experiences. This document surveys the new technologies introduced with iOS 7, and serves as a starting point for further exploration.

UIView Animation Enhancements

iOS 7 augments the animation support in UIKit, allowing applications to do things that previously required dropping directly into the Core Animation framework. For example, UIView can now perform spring animations as well as keyframe animations, which previously a CAKeyframeAnimation applied to a CALayer.

Spring Animations

UIView now supports animating property changes with a spring effect. To add this, call either the AnimateNotify or AnimateNotifyAsync method, passing in values for the spring damping ratio and the initial spring velocity, as described below:

springWithDampingRatio – A value between 0 and 1, where the oscillation increases for smaller value.

initialSpringVelocity – The initial spring velocity as a percentage of the total animation distance per second.

The following code produces a spring effect when the image view’s center changes:

This spring effect causes the image view to appear to bounce as it completes its animation to a new center location, as illustrated below:

Keyframe Animations

The UIView class now includes the AnimateWithKeyframes method for creating keyframe animations on a UIView. This method is similar to other UIView animation methods, except that an additional NSAction is passed as a parameter to include the keyframes. Within the NSAction, keyframes are added by calling UIView.AddKeyframeWithRelativeStartTime.

For example, the following code snippet creates a keyframe animation to animate a view’s center as well as to rotate the view:

The first two parameters to the AddKeyframeWithRelativeStartTime method specify the start time and duration of the keyframe, respectively, as a percentage of the overall animation length. The example above results in the image view animating to its new center over the first second, followed by rotating 90 degrees over the next second. Since the animation specifies UIViewKeyframeAnimationOptions.Autoreverse as an option, both keyframes animate in reverse as well. Finally, the final values are set to the initial state in the completion handler.

The screenshots below illustrates the combined animation through the keyframes:

UIKit Dynamics

UIKit Dynamics is a new set of APIs in UIKit that allow applications to create animated interactions based on physics. UIKit Dynamics encapsulates a 2D physics engine to make this possible.

The API is declarative in nature. You declare how the physics interactions behave by creating objects - called behaviors - to express physics concepts such as gravity, collisions, springs, etc. Then you attach the behavior(s) to another object, called a dynamic animator, which encapsulates a view. The dynamic animator takes cares of applying the declared physics behaviors to dynamic items - items that implement IUIDynamicItem, such as a UIView.

There are several different primitive behaviors available to trigger complex interactions, including:

UIAttachmentBehavior – Attaches two dynamic items such that they move together, or attaches a dynamic item to an attachment point.

This creates an image view centered at the top edge of the screen. To make the image “fall” with gravity, create an instance of a UIDynamicAnimator:

dynAnimator = new UIDynamicAnimator (this.View);

The UIDynamicAnimator takes an instance of a reference UIView or a UICollectionViewLayout, which contains the items that will be animated per the attached behavior(s).

Next, create a UIGravityBehavior instance. You can
pass one or more objects implementing the IUIDynamicItem, like a UIView:

var gravity = new UIGravityBehavior (dynItems);

The behavior is passed an array of IUIDynamicItem, which in this case contains the single UIImageView instance we are animating.

Finally, add the behavior to the dynamic animator:

dynAnimator.AddBehavior (gravity);

This results in the image animating downward with gravity, as illustrated below:

Since there is nothing constraining the boundaries of the screen, the image view simply falls off the bottom. To constrain the view so that the image collides with the edges of the screen, we can add a UICollisionBehavior. We'll cover this in the next section.

UICollisionBehavior

We'll begin by creating a UICollisionBehavior and adding it to the dynamic animator, just like we did for the UIGravityBehavior.

The UICollisionBehavior has a property called TranslatesReferenceBoundsIntoBoundry. Setting this to true causes the reference view’s bounds to be used as a collision boundary.

Now, when the image animates downward with gravity, it bounces slightly off the bottom of the screen before settling to rest there.

UIDynamicItemBehavior

We can further control the behavior of the falling image view with additional behaviors. For example, we could add a UIDynamicItemBehavior to increase the elasticity, causing the image view to bounce more when it collides with the bottom of the screen.

Adding a UIDynamicItemBehavior follows the same steps as with the other behaviors. First create the behavior:

With this behavior in place, the image view bounces more when it collides with the boundary.

General User Interface Changes

In addition to the new UIKit APIs such as UIKit Dynamics, Controller transitions, and enhanced UIView animations described above, iOS 7 introduces a variety of visual changes to the UI, and related API changes for various views and controls. For more information see the iOS 7 User Interface Overview.

Text Kit

Text Kit is a new API that offers powerful text layout and rendering features. It is built on top of the low level Core Text framework, but is much easier to use than Core Text.

Multitasking

iOS 7 changes when and how background work is performed. Task completion in iOS 7 no longer keeps applications awake when tasks are running in the background, and applications are woken for background processing in a non-contiguous manner. iOS 7 also adds three new APIs for updating applications with new content in the background:

Remote Notifications - Allows applications to update content when receiving a push notification. The notifications can be either silent or can display a banner on the lock screen.

Background Transfer Service – Allows uploading and downloading of data, such as large files, without a fixed time limit.

For more details about the new multitasking capabilities, see the iOS sections of the Xamarin Backgrounding guide.

Summary

This article covers several major new additions to iOS. First, it shows how to add custom transitions to View Controllers. Then, it shows how to use transitions in collection views, both from within a navigation controller, as well as interactively between collection views. Next, it introduces several enhancements made to UIView animations, showing how applications use UIKit for things that previously required programming directly against Core Animation. Finally, new UIKit Dynamics API, which brings a physics engine to UIKit, is introduced alongside the rich text support now available in the Text Kit framework.