Skip to content

Instantly share code, notes, and snippets.

@bachand
Created September 10, 2015 20:46

Revisions

  1. bachand created this gist Sep 10, 2015.
    24 changes: 24 additions & 0 deletions MasteringFocusExample5.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    class ActionHeroesView: UIView {
    let stalloneButton: UIButton
    let vanDammeButton: UIButton

    // ...

    override func didUpdateFocusInContext(context: UIFocusUpdateContext, withAnimationCoordinator coordinator: UIFocusAnimationCoordinator) {
    super.didUpdateFocusInContext(context, withAnimationCoordinator: coordinator)

    // we'll center Stallone when neither is in focus since he's a bigger deal
    let vanDammeFocused = (context.nextFocusedView == vanDammeButton)

    layoutIfNeeded()

    coordinator.addCoordinatedAnimations({
    self.stalloneCenterXConstraint.active = !vanDammeFocused
    self.vanDammeCenterXConstraint.active = vanDammeFocused

    self.layoutIfNeeded()
    },
    completion: nil
    )
    }
    }