I'm currently working on an Apple TV app. My view is build up from left to right like this (also see screenshot)
- small
UICollectionView
UIImageview
UIView
UILabels
UIButton
I can only focus the UIButton
on the right when I am on the second uicollectionviewCell
.
When I am on the first and third cell I'm not able to get the focus to the UIButton
.
Any help on this?
EDIT
I have this code in my ViewDidLoad
view.addLayoutGuide(focusGuide)
focusGuide.leftAnchor.constraintEqualToAnchor(collectionView.leftAnchor).active = true
focusGuide.topAnchor.constraintEqualToAnchor(collectionView.topAnchor).active = true
focusGuide.widthAnchor.constraintEqualToAnchor(view.widthAnchor).active = true
focusGuide.heightAnchor.constraintEqualToAnchor(view.heightAnchor).active = true
And added this method:
override func didUpdateFocusInContext(context: UIFocusUpdateContext, withAnimationCoordinator coordinator: UIFocusAnimationCoordinator) {
super.didUpdateFocusInContext(context, withAnimationCoordinator: coordinator)
guard let nextFocusedView = context.nextFocusedView else { return }
switch nextFocusedView {
case self.collectionView:
self.focusGuide.preferredFocusedView = self.orderButton
case self.orderButton:
self.focusGuide.preferredFocusedView = self.collectionView
default:
self.focusGuide.preferredFocusedView = nil
}
}