Animations

As someone who does work in mobile development for iOS and Android, the one thing that has really stood out to me is how accessible Apple's API for animations is. iOS uses an implicit animation API, which means that the programmer changes the properties of views and the operating system handles the interpolation, potentially with the developer defining what sort of timing function is used. What's most useful is that the property changes are just defined within a block of code, unlike the ridiculous APIs on some other platforms which have you specify layouts and property changes in XML files. This makes it incredibly easy to create animations that move views around the screen, resize them, and change properties like their color and alpha. 

While animations on iOS are quite easy to create, the API is not perfect. In the work I've been doing over the last four months I've actually run into two problems that Apple has addressed in iOS 10. The first is the issue of spring animations. The existing API for spring animations on iOS looks like the following:

// Animates with a spring effect
UIView.animate(withDuration: 1.0,
               delay: 0,
               usingSpringWithDamping: 0.8,
               initialSpringVelocity: 1.0

Now, anyone who has taken some sort of higher level math or physics course will probably notice something strange about this function. This function takes a damping value and an initial velocity for the spring. However, it also takes a duration value for the animation. This doesn't really make sense, because the duration of motion of a spring is dependent on its damping, stiffness, and mass properties. A proper spring animation API should not take a duration value; the duration should be a function of the spring properties. Because of this oddity the UIView spring animations API produces animations that have an artificial feel to them, and they rarely look like the true motion of a spring.

Interestingly enough, Apple's internal Core Animation API for spring animations works using the spring properties and doesn't take a duration. The strangeness of the UIView spring API isn't exactly unknown to its creators either:

In iOS 10 Apple has introduced a new class called UIViewPropertyAnimator. While I'm not going to go into the specifics of UIViewPropertyAnimator as they aren't directly relevant to non-developers, there are a few interesting things about it. The first is that it provides a new way of performing spring animations, and like Apple's internal API, it uses the physical properties of the spring to determine the duration of the animation. This should greatly improve how natural spring animations feel in third party applications, 

The second big issue I've run into is that there's no really good way to pause them or reverse UIView animations them. This doesn't sound like a huge issue when you consider simple animations. If you move a view 500 pixels left and you want to reverse it, then just move it 500 pixels to the right. It ends up being the same code but done in reverse. However, things get a lot more difficult when you have more complex animations, particularly in cases where you define specific keyframes for an animation. Any logic that you need to trigger after an animation also has to be reversed, and with each of these things the workload increases dramatically. My own example involves an eighty line keyframe animation to open a menu, which then had to be programmed in reverse to close the menu in the same manner. Naturally, this is also a source of bugs if something isn't done correctly in the reverse animation, and that creates an additional layer of difficulty and complexity.

With UIViewPropertyAnimator developers now have a way to control their animation as it progresses. The object has properties that specify the state of the animation, and it can be paused, reversed, and stopped at any point in the animation. This is a great improvement over the existing API, and it will allow developers to create more complex animations without having to worry about also creating the reverse logic. The API also provides a very easy way to create additive animations. For example, in the middle of an animation a developer could then add an animation that moves the views to a new position, and the API will take care of interpolating from the current state in the middle of the current animation to the new position specified in the added animation.

One last interesting point about UIViewPropertyAnimator is that it provides a way for developers to create and use their own timing functions. The timing function specifies how the state changes progress during the duration of the animation. For example, you could have an animation where a view moves a great distance during the start, but then slows down and takes much longer to reach its final position. Previously it was not really possible to do this, except with complicated timing work involving keyframes or chaining animations. While I doubt many developers will make use of this, it's a very helpful API for the cases where a developer wants to have control over the animation interpolation to give it a very unique look and feel.

Web Performance

With every release of iOS Apple makes performance improvements to the platform's underlying technologies. One of the areas where performance is often improved is Nitro, which is Apple's JavaScript engine. I always like to take a quick look at JavaScript performance on a newer and an older iOS device when Apple updates to a new major version, so I've run our standard smartphone review web benchmarks on the iPhone 5s and iPhone 6s running both iOS 9.3.5 and iOS 10 to see if there are any significant improvements.

  iPhone 5s iPhone 6s
Kraken (time in ms) iOS 9.3.5: 3372
IOS 10: 2956
iOS 9.3.5: 1706
IOS 10: 1504
WebXPRT 2015 (score) iOS 9.3.5: 115
IOS 10: 117
iOS 9.3.5: 207
IOS 10: 203
Jetstream (score) iOS 9.3.5: 57
IOS 10: 54
iOS 9.3.5: 119
IOS 10: 124

Overall there isn't much of an uplift in JavaScript performance going from iOS 9.3.5 to iOS 10. Kraken seems to show a small gain, but in WebXPRT and Jetstream the scores flip between favoring iOS 9 and iOS 10 depending on device, and the gaps are so small that they can be attributed to testing variance. Given that Apple has made some very big leaps in JavaScript performance during the last couple of years it's not really a surprise that the pace has slowed down.

Scrolling Performance

Something iOS has typically been known for is smooth scrolling performance. Apple's own standard is that views should animate at 60fps, which makes sense given the fact that iOS devices all use 60hz displays. There was a time where you really could expect near-constant 60fps animations throughout the system, barring really poorly designed applications. However, in recent years with increasing resolutions, greater pressure on the hardware, and more advanced visual effects, the smoothness of iOS has definitely degraded. Much of this has to do with the greater complexity of modern UIs, particularly ones that make heavy use of translucent views with blur.

In iOS 10 Apple has recognized that problems in their own APIs have played a part in dropping scrolling performance on iOS. This again goes back to the fact that views have become more complex on iOS in recent years. In the past, Apple's TableView and CollectionView APIs have prepared cells for rendering right before they are about to be displayed on the screen, and are removed right when they exit the screen. This doesn't pose a problem for something basic like a table cell with a couple of labels, but with complicated cells that use translucency, load high res images, and even have animated subviews, this method of rendering simply doesn't cut it. You can even have cases with CollectionViews like the iOS Photos app where you have to bring on many cells at the same time, all of which need to be set up individually. It's important to remember that there's only a ~16ms interval between frames, and the work to set up the UI for the next frame has to be completed in an even smaller period of time than that to manage a constant frame rate of 60fps.

To improving scroll performance Apple has changed the cell lifecycle in CollectionView and TableView APIs. As I mentioned before, the previous API essentially did everything relating to cell creation right before it was to be displayed on the screen, and cell removal right after it exited the screen. This caused two key issues. The first is that in the case of a CollectionView with many columns, every cell is rendered at once at that moment. This is a big cause of frame drops, as the hardware simply cannot render all the cells in time for the next frame. The second issue was the situation where a cell would exit one side of the screen and quickly be brought back on. This situation occurs frequently when a user accidentally scrolls past the item they were looking for in a list. In this case, the cell would have to be recreated from scratch despite having been on the screen only a moment before.

The iOS 10 APIs now spread out the work done during the lifecycle of a cell. Cells are now setup well before they need to be rendered, and the display process is spread out so a row of many cells doesn't need to be rendered at the exact same time right before they need to be shown on the screen. Cells are also kept for longer after they exit the screen, which means if the user quickly scrolls back the cell display method can simply be called again rather than having to get a new cell from the reuse queue, set it up, and draw it.

It honestly surprises me that Apple didn't make these changes sooner, because the impact on performance is dramatic. The iPhone 5s on iOS 10 has better scrolling performance than it ever has in the previous three years. This sort of thing is difficult to profile well even with XCode and Instruments, but I think it'll be immediately obvious to users that performance is improved, especially for users of older iOS devices that haven't had such a good time after being updated to iOS 8 and iOS 9.

Swift Playgrounds: Looking to the Future Final Words
Comments Locked

113 Comments

View All Comments

  • ApePriori - Wednesday, September 14, 2016 - link

    $399 for a 16GB SE, $549 for a 32GB 6s, $649 for a 32GB 7. More storage and Plus models will bump the price of course, but let's not pretend there are no options unless you spend over $800 dollars.
  • Lavkesh - Wednesday, September 14, 2016 - link

    Which is why Samsung isnt Android. They are a memory leak laden software mess.
  • robinthakur - Friday, September 23, 2016 - link

    Luckily for Samsung, their phones are just *exploding* in popularity so you probably don't need to worry about upgrading your S7 or Note 7 in 2 years because it will have been recalled.
  • Teknobug - Wednesday, September 14, 2016 - link

    Getting an Android through phone carrier causes the longer update times. If you get an Android phone directly from Google or directly from the manufacturer then updates comes pretty quick. Lenovo is the only one that dumped security updates.
  • robinthakur - Friday, September 23, 2016 - link

    Yes, it's just a shame that most consumers won't be buying their phones in this way so it's still a massive problem, more from a security perspective, for Android.
  • Lavkesh - Wednesday, September 14, 2016 - link

    And the fact that Nexus 5 isnt getting the Nougat update but much inferior hardware Android One devices are! So much so for dont be evil!
  • Xinn3r - Thursday, September 15, 2016 - link

    1. Maps also receives some really helpful widgets, including one for transit which allows you to check if there are any service advisories on your favorite transit lines, which has already helped me avoid delays due to subway and streetcar closures that I would not have thought to check for otherwise.

    I assume this is Google's map instead of Apple? Because I do have that widget for Google Map instead of Apple's own Map.

    2. In Notification Center you have a blurred background, and on the lock screen you get the current time and battery charge rather than the date.

    In your screenshot of the lock screen, you get current time and date instead of battery charge. I'm also not seeing the battery charge on my lock screen widget.
  • BulkSlash - Thursday, September 15, 2016 - link

    Really awesome review, as an iOS developer it's really great to see a review that focuses on API changes and the benefits they can bring to coders. More of this sort of thing please! :)

    It would be great to get Xcode on the iPad so I can quickly test out ideas on apps I'm developing if I have a flash of inspiration in the night or something. I definitely see the problems with security though, and also installing things like CocoaPods would be problematic.

    I also agree that the way Android handles animations is not good, I'm currently writing an Android app and video animations are currently impossible because the video goes blank during animations! It never does that in iOS!
  • beggerking@yahoo.com - Thursday, September 15, 2016 - link

    nothing interesting or new... Android has had those features/customization for YEARS and Years.

    and Crapple is still not customizable.
  • damianrobertjones - Monday, September 19, 2016 - link

    Maybe the standard user doesn't care to customize anything!?

Log in

Don't have an account? Sign up now