Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITextView not Scrolling in tvOS

I have a UITextView in my TV app, when i try to make it focusable then the UI is not making it focusable and i am unable to scroll it. I read some questions about it and some says that its a known issue and we should use storyboards. Actually i am using storyboards but still unable to get this to work. I have also tried to make it selectable, scrollEnabled and userInteractionEnabled and then finally also tried this line of code but none of them is working.

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

I also tried to print bounds abd contentSize of the 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 some body help 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 guess i should not be doing these many tricks but it is not working in any way. The focus is actually coming to UITextView but it does not scroll. Any ideas?

like image 506
Madu Avatar asked Nov 06 '15 11:11

Madu


3 Answers

I believe you want Indirect, not Direct touches. Here is how I set up my focusable, scrollable UITextView:

self.selectable = YES;
self.userInteractionEnabled = YES;
self.panGestureRecognizer.allowedTouchTypes = @[@(UITouchTypeIndirect)];
like image 144
Jess Bowers Avatar answered Nov 04 '22 01:11

Jess Bowers


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 it helps.

like image 7
AydinAngouti Avatar answered Nov 04 '22 00:11

AydinAngouti


For Swift 5, this is what worked for me:

    textView.isUserInteractionEnabled = true;
    textView.isScrollEnabled = true;
    textView.showsVerticalScrollIndicator = true;
    textView.bounces = true;
    textView.panGestureRecognizer.allowedTouchTypes = [NSNumber(value: UITouch.TouchType.indirect.rawValue)]
like image 7
Rados Avatar answered Nov 04 '22 00:11

Rados