use*_*930 0 uitableview uiscrollview ios swift
当用户滚动到顶部时,我设法禁用弹跳效果.我想以某种方式反转它,以便在底部禁用弹跳效果.你可以帮我修改我的代码吗?
var lastY: CGFloat = 0.0
func scrollViewDidScroll(scrollView: UIScrollView) {
let currentY = scrollView.contentOffset.y
let currentBottomY = scrollView.frame.size.height + currentY
if currentY > lastY {
//"scrolling down"
tableView.bounces = true
} else {
//"scrolling up"
// Check that we are not in bottom bounce
if currentBottomY < scrollView.contentSize.height + scrollView.contentInset.bottom {
tableView.bounces = false
}
}
lastY = scrollView.contentOffset.y
}
Run Code Online (Sandbox Code Playgroud)
您可以尝试此代码
override func scrollViewDidScroll(scrollView: UIScrollView)
{
if scrollView.contentOffset.y <= 0
{
scrollView.contentOffset = CGPointZero
}
}
Run Code Online (Sandbox Code Playgroud)
您是否尝试将反弹和 VerticalBounce 属性设置为NO。
您可以像这样以编程方式设置这些属性
在斯威夫特
tableView.bounces = false
tableView.alwaysBounceVertical = false
Run Code Online (Sandbox Code Playgroud)
在 Objective-C 中
tableView.bounces = NO;
tableView.alwaysBounceVertical = NO;
Run Code Online (Sandbox Code Playgroud)
或者
如果你想从Storyboard 中做到这一点。让你的tableview设置如下:
| 归档时间: |
|
| 查看次数: |
4488 次 |
| 最近记录: |