Чтобы добиться того, что вы пытаетесь сделать, вам необходимо установить следующие ограничения:
Scrollview:
- top
, leading
, trailing
и bottom
равные RootView «s top
, leading
, trailing
и bottom
WrapperView:
- top
, leading
, trailing
и bottom
равна ScrollView «s top
, leading
, trailing
и bottom
- width
равна ScrollView-х width
- height
GreaterThanOrEqual в ScrollView-х height
TextView:
- top
, leading
и trailing
равно WrapperView 's top
, leading
и trailing
FooterView:
- leading
и trailing
равной WrapperView' s leading
и trailing
- bottom
равно WrapperView «ы bottom
(с постоянными 15)
- top
moreThanOrEqual to TextView «ы bottom
(с константой 15)
Ключ являются два ограничения, которые используют greaterThanOrEqual
соотношение: WrapperView, по крайней мере столь же высоко, как ScrollView и FooterView` ы ТОП по крайней мере, на расстоянии 15 от TextView.
Вот ограничения при использовании раскадровки:
И это, как вы могли бы сделать это программно (с помощью SnapKit):
import UIKit
import SnapKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let scrollView = UIScrollView()
view.addSubview(scrollView)
let wrapperView = UIView()
wrapperView.backgroundColor = .cyan
scrollView.addSubview(wrapperView)
let textView = UILabel()
textView.numberOfLines = 0
textView.font = UIFont.systemFont(ofSize: 30)
textView.text = "You think water moves fast? You should see ice. It moves like it has a mind. Like it knows it killed the world once and got a taste for murder. After the avalanche, it took us a week to climb out. Now, I don't know exactly when we turned on each other, but I know that seven of us survived the slide... and only five made it out. Now we took an oath, that I'm breaking now. We said we'd say it was the snow that killed the other two, but it wasn't. Nature is lethal but it doesn't hold a candle to man."
//textView.text = "You think water moves fast? You should see ice. It moves like it has a mind."
textView.backgroundColor = .yellow
wrapperView.addSubview(textView)
let footer = UILabel()
footer.textAlignment = .center
footer.text = "Footer text"
footer.backgroundColor = .orange
wrapperView.addSubview(footer)
scrollView.snp.makeConstraints { (make) in
make.edges.equalTo(view)
}
wrapperView.snp.makeConstraints { (make) in
make.edges.equalTo(scrollView)
make.width.equalTo(scrollView)
make.height.greaterThanOrEqualTo(scrollView)
}
textView.snp.makeConstraints { (make) in
make.top.left.right.equalTo(0)
}
footer.snp.makeConstraints { (make) in
make.top.greaterThanOrEqualTo(textView.snp.bottom).offset(15)
make.left.right.equalTo(0)
make.bottom.equalTo(-15)
}
}
}
Скриншот с длинным текстом:
Скриншот с коротким текстом:
добавить колонтитул ниже UIScrollView и показать его, проверяя конец свитка в scrollviewDidScroll – zombie
@zombie Он также включает в себя много логики в коде – user2786037