Scroll in UIScrollView with tvOS
Asked Answered
G

4

9

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

Galinagalindo answered 15/8, 2017 at 15:18 Comment(3)
How you are setting the constraint?Dickie
Is your UITextView editable? If you UITextView is editable then the scrolling of UIScrollView won't work.Latency
1) I am setting constraints using Interface Builder 2) my TextView is not editableGalinagalindo
B
3

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.

Biodynamics answered 13/8, 2018 at 12:21 Comment(1)
correct, and you need to also set the allowedTouchTypes on the scrollview's panGestureRecognizer: self.scrollView.panGestureRecognizer.allowedTouchTypes = @[@(UITouchTypeIndirect)];Seismoscope
C
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

Catinacation answered 21/8, 2017 at 3:38 Comment(1)
You only need to allow the touch gesture on the scrollview: scrollView.panGestureRecognizer.allowedTouchTypes = [NSNumber(value:UITouchType.indirect.rawValue)]Cribbing
J
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

Jacintajacinth answered 21/8, 2017 at 11:36 Comment(1)
unfortunately it didn't helpGalinagalindo
S
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

Sculptor answered 24/8, 2017 at 6:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.