【发布时间】:2019-01-15 14:56:39
【问题描述】:
我在滚动视图之外有一个标签。我想在滚动视图上下滚动时将标签从屏幕的左到右移动,反之亦然。我编写了这段代码,它在滚动视图以正常速度滚动并且滚动非常快时标签x位置变化非常缓慢时工作。我怎样才能为所有滚动视图滚动速度做到这一点?
func scrollViewDidScroll(_ scrollView: UIScrollView!) {
let offset = scrollView.contentOffset.y
let imahey = view.convert(placeImgview.frame, from:scrollview).origin.y + placeImgview.frame.width
print(offset)
let ratio: CGFloat = (-offset*1.0 / placeImgview.frame.height)
topBarView.alpha = -ratio
if placeName.frame.origin.x < -20 {
placeName.center = CGPoint(x: placeName.center.x - 3*ratio, y: placeName.center.y + ratio/1.5)
}
if (self.lastContentOffset > scrollView.contentOffset.y) {
placeName.center = CGPoint(x: placeName.center.x + 6*ratio, y: placeName.center.y - 2*ratio)
if offset == -20 {
placeName.frame.origin.x = -view.frame.width/2
placeName.frame.origin.y = 60
}
}
self.lastContentOffset = scrollView.contentOffset.y
}
【问题讨论】:
标签: ios swift uiscrollview