UITextView不在tvOS中滚动

问题描述 投票:5回答:5

我在我的电视应用程序中有一个UITextView,当我尝试使其可聚焦时,UI不会使其可聚焦,我无法滚动它。我读了一些关于它的问题,有些人说它是一个已知的问题,我们应该使用故事板。实际上我正在使用故事板但仍然无法使其工作。我也尝试使它成为selectablescrollEnableduserInteractionEnabled然后最后也尝试了这行代码,但它们都没有工作。

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

我也尝试打印qazxsw poi的qazxsw poi和qazxsw poi,这里是日志

bounds

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

contentSize

我想我不应该做这么多技巧,但它不会以任何方式工作。焦点实际上是来到UITextView但它不滚动。有任何想法吗?

ios swift uitextview tvos apple-tv
5个回答
8
投票

我相信你想要间接,而不是直接接触。以下是我如何设置可聚焦,可滚动的UITextView:

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

5
投票

在Swift 2.1中,这对我有用:

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


}

希望能帮助到你。


3
投票

基于之前的答案,以下是Swift 3.0.1中对我有用的内容:

  • 我不得不继承UITextView来覆盖self.selectable = YES; self.userInteractionEnabled = YES; self.panGestureRecognizer.allowedTouchTypes = @[@(UITouchTypeIndirect)]; 以返回myTextView.userInteractionEnabled = true myTextView.selectable = true myTextView.scrollEnabled = true myTextView.panGestureRecognizer.allowedTouchTypes = [UITouchType.Indirect.rawValue]
  • 我不得不设置UITextView
  • 我不得不在代码中设置canBecomeFocused - 在Interface Builder中设置它似乎不够
  • 我必须在“界面”构建器中选中“滚动已启用”(在代码中设置true也可以

我找到的其他一些细节:

  • panGestureRecognizer.allowedTouchTypes = [NSNumber(value: UITouchType.indirect.rawValue)]使滚动感觉更自然(必须在代码中设置; IB设置不受尊重)
  • isUserInteractionEnabled = true必须在代码中设置; IB设置不受尊重
  • 覆盖isScrollEnabled = true以更改背景颜色以直观地指示焦点。

1
投票

对于Swift 4,这对我有用:

bounces = true

0
投票

如果您使用objective-C来执行此操作,那将是非常示例:

showsVerticalScrollIndicator = true

以上这些就足够了,但是,如果你使用swift来做这件事,它就行不通了。

© www.soinside.com 2019 - 2024. All rights reserved.