0
A
回答
1
你可以使用这个滚动视图代表。例如,
func scrollViewDidScroll(_ scrollView: UIScrollView) {
if scrollView.panGestureRecognizer.translation(in: scrollView.superview).y > 0 {
//scrolling downwards
if scrollView.contentOffset.y < 0 {
//this means we are at top of the scrollView
changeSectionHeight(with scrollView.contentOffset.y, hide:false)
}
}
else {
//we are scrolling upward
changeSectionHeight(with scrollView.contentOffset.y, hide:true)
}
}
这是用户如何滚动向下或向上滚动的方式。现在基于此,我们可以隐藏或显示顶部部分(通过更改高度约束)。
//make IBoutlet for the top section height constraint
@IBOutlet weak var topSectionHeightConstraint: NSLayoutConstraint!
func changeSectionHeight(with offset:CGFloat, hide:Bool) {
let requiredHeight: CGFloat = hide ? 0.0 : 160.0 //let say when you want to hide the height is 0.0 and when you want to show it its 160.0
//If you want animation when showing and hiding use animate if not then simply change the constant for the constraint
if hide {
if (holderViewHeightConstraint.constant - offset) > requiredHeight {
UIView.animate(withDuration: 0.3, animations: {
self. topSectionHeightConstraint.constant -= offset
})
}
else {
UIView.animate(withDuration: 0.3, animations: {
self. topSectionHeightConstraint.constant = requiredHeight
})
}
}
else {
if (holderViewHeightConstraint.constant - offset) < requiredHeight {
UIView.animate(withDuration: 0.3, animations: {
self. topSectionHeightConstraint.constant -= offset
})
}
else {
UIView.animate(withDuration: 0.3, animations: {
self. topSectionHeightConstraint.constant = requiredHeight
})
}
}
}
相关问题
- 1. 滚动时隐藏bootstrap导航栏
- 2. 隐藏导航向下滚动并仅在移动时向上滚动
- 3. 如何在滚动时隐藏导航栏
- 4. 如何隐藏导航栏?
- 5. 修复导航栏上向下滚动
- 6. 隐藏导航栏?
- 7. 页面菜单,滚动时隐藏导航栏
- 8. 滚动时隐藏和显示导航栏
- 9. 水平滚动垂直导航栏 - 滚动时导航栏下的内容
- 10. 的UIButton向上滑动时,导航栏隐藏
- 11. 将导航栏移动到顶部,同时向下滚动HTML
- 12. 当页面向下滚动时,导航栏移动到顶部
- 13. 隐藏滚动导航栏 - 运动员的WordPress主题
- 14. 如何使用React向下滚动导航栏?
- 15. 如何隐藏lightSlder的导航栏?
- 16. 如何使用Jquery隐藏导航栏?
- 17. 如何在android中隐藏导航栏?
- 18. 如何隐藏Ionic2中的导航栏
- 19. 如何通过CAAnimation隐藏导航栏?
- 20. 如何解决Bootstrap导航栏隐藏
- 21. 如何隐藏导航栏上的UIbarbutton
- 22. 隐藏导航栏导致视图向上移动
- 23. 隐藏导航栏旋转
- 24. 问题隐藏导航栏
- 25. SFSafariViewController:隐藏导航栏
- 26. IPHONE:ABPeoplePickerNavigationController隐藏导航栏
- 27. Nativescript - 隐藏导航栏(IOS)
- 28. 固定导航向下滚动时
- 29. 向下滚动时显示导航
- 30. 导航抽屉打开时如何隐藏滚动条
如何在代码中更改高度约束? – Riccardo
增加了改变高度的功能。没有测试,但你可以调整你想要的结果。 – kathayatnk