当用户在滚动视图中滑动时尝试将thumbImage设置为alpha = 1,但是现在这取决于我在屏幕上开始滑动的位置。如果我长扫,则Alpha值= 1,短扫会使它更透明。我希望总是在显示scrollview(collectionView)中的新页面时始终为alpha = 1。我该如何更改?
func scrollViewDidScroll(_ scrollView: UIScrollView) {
let currentX = scrollView.panGestureRecognizer.translation(in: scrollView.superview).x
let currentXSign = Int(currentX).signum()
if currentXSign != lastXSign &&
currentXSign != 0{
}
if lastXSign < 0 {
thumbImage.isHidden = false
thumbImage.alpha = abs(currentX) / view.center.x
thumbImage.image = #imageLiteral(resourceName: "thumbsdown")
print("SCROLLING RIGHT")
} else if lastXSign > 0 {
thumbImage.isHidden = false
thumbImage.alpha = abs(currentX) / view.center.x
thumbImage.image = #imageLiteral(resourceName: "thumbsup")
print("SCROLLING LEFT")
}
lastXSign = currentXSign
}