【问题标题】:Apple TV Default Scrolling behaviour for UIScrollView with a UITextView?带有 UITextView 的 UIScrollView 的 Apple TV 默认滚动行为?
【发布时间】:2017-04-20 15:26:00
【问题描述】:

是否可以让 UIScrollView 表现得像网站上看到的普通滚动窗口?意思是不通过关注滚动视图内的不同 UIView 来滚动。我有一个长 UITextView,它以可变高度展开,我希望用户正常滚动并阅读文本。

但是将 UITextView 添加到 UIScrollView(都具有给定的 contentSize)不会给我任何结果。

已实施:

    //::  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)

【问题讨论】:

    标签: swift3 uiscrollview uitextview apple-tv


    【解决方案1】:

    就像删除UIScrollView 并启用UITextView 上的滚动一样简单:

    txtView.isScrollEnabled = true
    

    很惊讶没有人回答这个问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-23
      • 1970-01-01
      • 2011-03-19
      • 1970-01-01
      • 1970-01-01
      • 2019-01-31
      相关资源
      最近更新 更多