试试这个
func scrollViewDidScroll(_ scrollView: UIScrollView) {
updateGradientFrame()
//On the scroll view content is over means there is no content anymore then hide the mask
if scrollView.contentOffset.y >= scrollView.contentSize.height - scrollView.bounds.height {
label.layer.mask = nil
} else {
//Else show the mask of UILabel
label.layer.mask = gradient
}
}
更新:
private func updateGradientFrame() {
gradient.frame = CGRect(
x: 0,
y: scrollView.contentOffset.y,
width: scrollView.bounds.width,
height: scrollView.bounds.height
)
}
GITHUB URL:
https://github.com/sateeshyegireddi/GradientScrollViewDemo