UITextView not scrolling in tvOS

I have a UITextView in my TV application, when I try to make it focused, then the user interface does not make it focused, and I can not scroll it. I read some questions about this, and some say this is a known issue, and we should use storyboards. I actually use storyboards, but still can't get it to work. I also tried to make it selectable , scrollEnabled and userInteractionEnabled , and then finally tried this line of code, but none of them work.

 descriptionLbl.panGestureRecognizer.allowedTouchTypes = [NSNumber(integer: UITouchType.Direct.rawValue)] 

I also tried to print bounds abd contentSize UITextView and here is the log

 Content Size (740.0, 914.0) Bounds (25.0, 0.0, 740.0, 561.0) 

Here is my code can help someone me

 @IBOutlet weak var descriptionLbl: UITextView! var currentModel : Model? override func viewDidLoad() { super.viewDidLoad() descriptionLbl.selectable = true descriptionLbl.scrollEnabled = true descriptionLbl.userInteractionEnabled = true descriptionLbl.panGestureRecognizer.allowedTouchTypes = [NSNumber(integer: UITouchType.Direct.rawValue)] descriptionLbl.text = (currentModel?.description)! + (currentModel?.description)! + (currentModel?.description)! descriptionLbl?.contentInset = UIEdgeInsets(top: 0.0, left: -25.0, bottom: 0.0, right: 0.0); } 

I think I should not do these many tricks, but it does not work in any way. The focus is actually approaching a UITextView , but it does not scroll. Any ideas?

+5
source share
5 answers

I believe that you need indirect, not direct touches. This is how I customize my custom, scrollable UITextView:

 self.selectable = YES; self.userInteractionEnabled = YES; self.panGestureRecognizer.allowedTouchTypes = @[@(UITouchTypeIndirect)]; 
+8
source

Here is what worked for me in Swift 2.1:

 myTextView.userInteractionEnabled = true myTextView.selectable = true myTextView.scrollEnabled = true myTextView.panGestureRecognizer.allowedTouchTypes = [UITouchType.Indirect.rawValue] 

Hope this helps.

+5
source

Here is what worked for me in Swift 3.0.1 based on previous answers:

  • I had to subclass UITextView to override canBecomeFocused to return true
  • I had to set panGestureRecognizer.allowedTouchTypes = [NSNumber(value: UITouchType.indirect.rawValue)]
  • I had to set isUserInteractionEnabled = true in the code - installing it in Interface Builder did not seem sufficient
  • I had to check "Scrolling enabled" in the interface builder (setting isScrollEnabled = true in the code will also work

A few other subtleties that I found:

  • bounces = true made scrolling more natural (it had to be set in code, IB setting was not respected)
  • showsVerticalScrollIndicator = true should have been set in code; IB setting is not respected.
  • Overriding didUpdateFocus(in:with:) to change the background color to visually indicate focus.
+3
source

For Swift 4, this is what worked for me:

  textView.isUserInteractionEnabled = true; textView.isScrollEnabled = true; textView.showsVerticalScrollIndicator = true; textView.bounces = true; textView.panGestureRecognizer.allowedTouchTypes = [NSNumber(value: UITouchType.indirect.rawValue)] 
+1
source

If you use target-C for this, this will be a very example:

  _textView.panGestureRecognizer.allowedTouchTypes = @[@(UITouchTypeIndirect)]; _textView.selectable = YES; _textView.scrollEnabled = YES; _textView.userInteractionEnabled = YES; 

Above this is enough, however, if you use swift for this, it will not work.

0
source

All Articles