7

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

moonvader
  • 13,845
  • 14
  • 51
  • 93

4 Answers4

2

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.

Michele Dall'Agata
  • 1,304
  • 2
  • 12
  • 25
  • correct, and you need to also set the allowedTouchTypes on the scrollview's panGestureRecognizer: `self.scrollView.panGestureRecognizer.allowedTouchTypes = @[@(UITouchTypeIndirect)];` – Mr. Zystem Jun 01 '20 at 11:50
0

I think you can use the

func gestureRecognizer (_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool 

method to judge the view and scroll it

According to the view you touch to do something to intercept

雪夜风暴
  • 158
  • 11
  • 1
    You only need to allow the touch gesture on the scrollview: scrollView.panGestureRecognizer.allowedTouchTypes = [NSNumber(value:UITouchType.indirect.rawValue)] – Leon Feb 19 '18 at 14:32
0

There is some way to fix your problem.

  1. Please check your scrollview in storyboard, is your scrolling or vertical indicator is checked?
  2. U can make your textview scrollable if u just want to scroll the textview content
  3. There is problem in your constraint, you need to cleary add the height, vertical space top, vertical space bottom from your textview to your scrollview.

Hope these advice can help you

antonio yaphiar
  • 382
  • 2
  • 8
0

So you have to set the scrollview's content size larger than the scrollview bounds, so you should set contentsize to (400, 800), probaly in you xib

ovidiur
  • 308
  • 2
  • 9