Search code examples
swift3uiscrollviewuitextviewapple-tv

Apple TV Default Scrolling behaviour for UIScrollView with a UITextView?


Is it possible to have a UIScrollView behave like a normal scroll window as seen on say a website? Meaning not scrolling by focusing on different UIViews inside the scroll view. I have a long UITextView that expands at a variable height and I would like the user to scroll normally and read the text.

But adding a UITextView to a UIScrollView (Both with a given contentSize) does not give me any results.

As implemented:

    //::  Scroll View
    scrollView = UIScrollView(frame: CGRect(x: 0, y: 0, width: 1920, height: 1080))
    scrollView.autoresizingMask = [.flexibleHeight]
    scrollView.translatesAutoresizingMaskIntoConstraints = true
    scrollView.backgroundColor = UIColor.red


    scrollView.addSubview(txtView)
    view.addSubview(scrollView)

    //::  Anchor
    txtView.translatesAutoresizingMaskIntoConstraints = false;
    txtView.topAnchor.constraint(equalTo: view.topAnchor, constant: 120).isActive = true
    txtView.centerXAnchor.constraint(equalTo: view.centerXAnchor, constant: 0).isActive = true
    txtView.widthAnchor.constraint(equalToConstant: 825).isActive = true
    txtView.contentSize = CGSize(width: 825, height: 2000)
    txtView.clipsToBounds = false

    scrollView.isScrollEnabled = true
    scrollView.showsVerticalScrollIndicator = true
    scrollView.contentSize = CGSize(width: 1920, height: 2000)

Solution

  • Was as easy as removing the UIScrollView and enable scrolling on the UITextView:

    txtView.isScrollEnabled = true
    

    Surprised no one answered that.