Skip to content

Instantly share code, notes, and snippets.

View romaonthego's full-sized avatar

Roman Efimov romaonthego

View GitHub Profile

Hacking UIView animation blocks for fun and profit

In this article, I'm going to explore a way that we can create views that implement custom Core Animation property animations in a natural way.

As we know, layers in iOS come in two flavours: Backing layers and hosted layers. The only difference between them is that the view acts as the layer delegate for its backing layer, but not for any hosted sublayers.

In order to implement the UIView transactional animation blocks, UIView disables all animations by default and then re-enables them individually as required. It does this using the actionForLayer:forKey: method.

Somewhat strangely, UIView doesn't enable animations for every property that CALayer does by default. A notable example is the layer.contents property, which is animatable by default for a hosted layer, but cannot be animated using a UIView animation block.

// Playground - noun: a place where people can play
import Foundation
enum Result<ValueType, ErrorType> : LogicValue {
case Value(ValueType)
case Error(ErrorType)
var successful : Bool {
get {
class AccountStore {
// Doesn't work yet
class var sharedStore = ACAccountStore()
// This works although I'm unsure of the optional
class func sharedStore() -> ACAccountStore {
var store: ACAccountStore? = nil
var token: dispatch_once_t = 0
dispatch_once(&token, {