Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scroll in UIScrollView with tvOS

I stuck with scrolling content inside UIScrollView in my tvOS app.

I have scrollView with height = 400 and width = 400. Inside this scrollview I have non-scrollable UITextView with height = 800 and width = 400. So I want to scroll this text.

But my scroll view is not scrolled, I don't see any scrolling indicators and also my scrollView have isFocused value = false. How can I solve this problem?

p.s. update I created separate ViewController (image below). It have black ScrollView and white view with big height with label in the middle of it. ScrollView has fixed width and height and there is no scrolling for some reason! I even didn't connect any separate class - just created it from Interface builder.

enter image description here

like image 859
moonvader Avatar asked Aug 15 '17 15:08

moonvader


1 Answers

UIView isn't focusable by default (and as such in tvOS it can't be scrolled) . You have to subclass it to override canBecomeFocused:

class myUIView: UIView {
    override var canBecomeFocused: Bool {
        return true
    }
}

Then in your example use the class myUIView instead of UIView for your long white view. Setting the right constraints you wouldn't need to design the views out of the controller view boundaries in IB either. Check this answer with the linked gist to see how to build the constraints.

like image 86
Michele Dall'Agata Avatar answered Sep 20 '22 07:09

Michele Dall'Agata