Skip to content

Instantly share code, notes, and snippets.

@dedeexe
Created November 6, 2015 10:30

Revisions

  1. dedeexe created this gist Nov 6, 2015.
    41 changes: 41 additions & 0 deletions CustomFocusView.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@
    //
    // FocusView.swift
    // CustomNavigation
    //
    // Creating a CustomFocusView
    // This code shows how to implement a custom view that can be focused in tvOS
    // Just set this class as an UIView's custom class
    //

    import UIKit

    class CustomFocusView: UIView {


    //Now This View controller can get Focus
    override func canBecomeFocused() -> Bool {
    return true
    }

    //We Can chance the focus behavior.... Is a good idea if we evidence it
    override func didUpdateFocusInContext(context: UIFocusUpdateContext, withAnimationCoordinator coordinator: UIFocusAnimationCoordinator) {

    //Bahavior we will trigger when view lost focus
    if context.previouslyFocusedView === self
    {
    UIView.animateWithDuration(0.1, animations: { () -> Void in
    context.previouslyFocusedView?.transform = CGAffineTransformMakeScale(1.0, 1.0)
    })
    }

    //Bahavior we will trigger when view get focus
    if context.nextFocusedView === self
    {
    UIView.animateWithDuration(0.1, animations: { () -> Void in
    context.nextFocusedView?.transform = CGAffineTransformMakeScale(1.2, 1.2)
    })
    }

    }

    }