Search code examples
swiftuiscrollviewtvos

UIScrollView in tvOS


I have a view hierarchy similar to the one in the image below (blue is the visible part of the scene):

enter image description here

So I have a UIScrollView with a lot of elements, out of which I am only showing the two button since they are relevant to the question. The first button is visible when the app is run, whereas the other one is positioned outside of the initially visible area. The first button is also the preferredFocusedView.

Now I am changing focus between the two buttons using a UIFocusGuide, and this works (checked it in didUpdateFocusInContext:). However, my scroll view does not scroll down when Button2 gets focused.

The scroll view is pinned to superview and I give it an appropriate content size in viewDidLoad of my view controller.

Any ideas how to get the scroll view to scroll?


Solution

  • Finally I solved this by setting scrollView.contentSize to the appropriate size in viewDidLoad.