-
-
Save PratheeshDBennet/4267645bef71cb733bb87c8e113973f8 to your computer and use it in GitHub Desktop.
Creating a custom focus view for tvOS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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) | |
}) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment