I have a UICollectionView which contains 12-13 UICollectionViewCells. I can easily focus on the UICollectionViewCells and everything works. There is a UIButton outside the U
Jess Bowers solution is almost there but Xcode says UIButton
s doesn't have topAnchor
property and the solution given by Jess doesn't work for me.
For me, the solution was to create a huge view with the same width as the UICollectionView
on top of it. See picture.
The code will be this:
UIFocusGuide *topButtonFocusGuide = [[UIFocusGuide alloc] init];
topButtonFocusGuide.preferredFocusedView = myButton;
[self.view addLayoutGuide:topButtonFocusGuide];
[self.view addConstraints:@[
[topButtonFocusGuide.topAnchor constraintEqualToAnchor:transparentView.topAnchor],
[topButtonFocusGuide.bottomAnchor constraintEqualToAnchor:transparentView.bottomAnchor],
[topButtonFocusGuide.leadingAnchor constraintEqualToAnchor:transparentView.leadingAnchor],
[topButtonFocusGuide.widthAnchor constraintEqualToAnchor:transparentView.widthAnchor],
]];