2015-11-06 81 views
5

我在我的电视应用程序中有一个UITextView,当我尝试使它可以焦点时,然后用户界面没有使其可聚焦,我无法滚动它。我读了一些关于它的问题,有人说它是一个已知的问题,我们应该使用故事板。其实我正在使用故事板,但仍然无法得到这个工作。我也试图使它selectable,scrollEnableduserInteractionEnabled然后最后也尝试了这一行代码,但他们都没有工作。UITextView不滚动在tvOS

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

我也试图打印bounds ABD中UITextViewcontentSize这里是日志

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

这里是我的代码可一些身体帮我

@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); 


} 

我想我应该不要做这些许多技巧,但它不以任何方式工作。重点实际上是UITextView,但它不滚动。有任何想法吗?

回答

7

我相信你想要间接,而不是直接触摸。这里是我建立了我的可调焦,可滚动的UITextView:

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

它是如何聚焦的? – user3160965

+0

通过使其userInteractionEnabled,它可以自动聚焦 –

4

这里是为我工作,在雨燕2.1:

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

希望它能帮助。

+0

'scrollEnabled'似乎是默认情况下,所以也许多余 – Andrei

2

下面是我在斯威夫特3.0.1什么工作的基础上,以前的答案:

  • 我不得不继承UITextView覆盖canBecomeFocused返回true
  • 我必须设置panGestureRecognizer.allowedTouchTypes = [NSNumber(value: UITouchType.indirect.rawValue)]
  • 我必须在代码中设置isUserInteractionEnabled = true - 将其设置在Interface Builder中似乎不够用
  • 我必须在界面构建器中检查“滚动已启用”(设置isScrollEnabled = true i n个代码也将工作

其他一些细微,我发现:

  • bounces = true做出滚动的手感更自然(必须在代码中设置; IB设置不受尊重)
  • showsVerticalScrollIndicator = true必须在代码中设置; IB设置不受尊重
  • 覆盖didUpdateFocus(in:with:)更改背景颜色以直观指示焦点。
+0

“无法覆盖mutable属性只读属性isScrollEnabled'” – abhishek

+0

它给出了上述错误,同时设置属性isScrollEnabled在最新的swift 3和xcode版本中。 – abhishek

+0

你不需要使用“canBecomeFocused返回true”,但这仍然是一个很大的帮助 – reggie