我在一個視圖上有一個 ScrollView,頁面控制元件從底部粘在一起。當頁面從頁面底部滾動到 48px 并保持不透明度 100%(顯示)到頁面末尾時,頁面控制元件將被影片化并顯示。但我無法檢測到這種行為。scrollView 內容大小在下面提到。
ScrollView 內容大小:
寬度:414.0 高度:852.0
我正在使用以下代碼。
//MARK: - ScrollView Delegate
extension RemoveViewController: UIScrollViewDelegate {
func scrollViewDidScroll(_ scrollView: UIScrollView) {
let distanceFromBottom = scrollView.contentSize.height - scrollView.contentOffset.y
print(distanceFromBottom)
if distanceFromBottom >= 796 {
print(" you reached at desired bottom")
self.showPageControl(toShow: true)
} else {
self.showPageControl(toShow: false)
}
}
}
func showPageControl(toShow: Bool) {
if toShow {
if self.pageControl.alpha != 1 {
UIView.animate(withDuration: 0.300, animations: {
self.pageControl.alpha = 1
})
}
} else {
if self.pageControl.alpha != 0 {
UIView.animate(withDuration: 0.300, animations: {
self.pageControl.alpha = 0
})
}
}
}
請讓我知道我在這里做錯了什么。
uj5u.com熱心網友回復:
您需要計算第bottomOffset一個,然后計算它與contentOffset. 如果它 <= 56,那么你到達了一個特定的位置。
let bottomOffset = scrollView.contentSize.height - scrollView.frame.size.height
let position = bottomOffset - scrollView.contentOffset.y
if position <= 56 {
print(" you reached at desired bottom")
self.showPageControl(toShow: true)
} else {
self.showPageControl(toShow: false)
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/405069.html
標籤:
上一篇:為每個部分選擇單個單元格的問題
下一篇:突出顯示UITextView文本
