停止 ScrollView 越过 &低于界限 [英] Stopping ScrollView Going Above & Below The Bounds
问题描述
我在 ViewController 中创建了一个 UIScrollView 并添加了 UIView &UITableView 作为 ViewController 的兄弟.
I created a UIScrollView in a ViewController and added UIView & UITableView as siblings of ViewController.
var pageSize = view.bounds.size
// MiniQuestion: I disabled vertical indicators but it caused a gap for the width
// of the indicator, so I added the gap manually. Is it okay behaviour?
pageSize.width += 5
MyView.backgroundColor = UIColor.redColor()
MyTableView.backgroundColor = UIColor.blueColor()
let pagesViews = [MyView , MyTableView]
let numberOfPages = pagesViews.count
for (pageIndex,page) in pagesViews.enumerate(){
page.frame = CGRect(origin: CGPoint(x:0 , y:CGFloat(pageIndex) * pageSize.height), size: pageSize)
ScrollView.addSubview(page)
}
ScrollView.contentSize = CGSize(width: pageSize.width, height: pageSize.height * CGFloat(numberOfPages))
效果很好.除了,即使我有 2 个页面并向 ScrollView 添加了约束,它也会在顶部页面上方(当我拉更多时)和在 tableview 页面的末尾下方(当我推更多时).但是我想将它滚动到 tableview 的末尾并卡在顶部的边界处.
It's working nice. Except, even though I have 2 pages and added constraints to ScrollView, it's going above the top page (when I pull more) and below the end of tableview page (when I push more). However I want to scroll it until the end of the tableview and stuck at the bound of the top.
通常它们看起来不错......但是,
Normally they look fine... However,
如果我超越顶部:
如果我推到底部:
如何防止这种行为?
推荐答案
如果您不想让用户将其拉出滚动视图的边界,则:
If you don't want to enable user to pull it beyond the bounds of scroll view then:
ScrollView.bounces = false
这篇关于停止 ScrollView 越过 &低于界限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!