Last active
January 18, 2016 17:01
-
-
Save BradB132/ebfff987cea256f444ff to your computer and use it in GitHub Desktop.
Focus_in_tvOS
This file contains hidden or 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
import UIKit | |
class ViewController: UIViewController { | |
@IBOutlet var buttonA:UIButton! | |
@IBOutlet var buttonB:UIButton! | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
let focusGuide = UIFocusGuide() | |
focusGuide.preferredFocusedView = buttonB | |
view.addLayoutGuide(focusGuide) | |
view.addConstraint(NSLayoutConstraint(item: focusGuide, | |
attribute: .Width, | |
relatedBy: .Equal, | |
toItem: buttonA, | |
attribute: .Width, | |
multiplier: 1, | |
constant: 0)) | |
view.addConstraint(NSLayoutConstraint(item: focusGuide, | |
attribute: .Height, | |
relatedBy: .Equal, | |
toItem: buttonA, | |
attribute: .Height, | |
multiplier: 1, | |
constant: 0)) | |
view.addConstraint(NSLayoutConstraint(item: focusGuide, | |
attribute: .CenterX, | |
relatedBy: .Equal, | |
toItem: buttonB, | |
attribute: .CenterX, | |
multiplier: 1, | |
constant: 0)) | |
view.addConstraint(NSLayoutConstraint(item: focusGuide, | |
attribute: .CenterY, | |
relatedBy: .Equal, | |
toItem: buttonA, | |
attribute: .CenterY, | |
multiplier: 1, | |
constant: 0)) | |
} | |
//MARK: - UIFocusEnvironment | |
override func didUpdateFocusInContext(context: UIFocusUpdateContext, withAnimationCoordinator coordinator: UIFocusAnimationCoordinator) { | |
//TODO: update the 'preferredFocusView' of our focusGuide depending on which view is now in focus | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment