使用 Scrollview 的 contentOffset 计算 Imageview Frame
Calculate Imageview Frame with Scrollview's contentOffset
我正在尝试计算我的 scrollViewDidScroll 中的图像帧。当我向下或向上下拉我的 tableview 时,我想更改我的 imageview 框架。
if (scrollView.contentOffset.y > 0 && scrollView.contentOffset.y <= 60) {
userImageViewHeightConstraint.constant = 50 - scrollView.contentOffset.y /6;
userImageViewWidthConstraint.constant = 50 - scrollView.contentOffset.y /6;
userImageView.layer.cornerRadius = userImageViewHeightConstraint.constant/2;
}
我是这样计算的,但是,我习惯于 0 到 60 之间的内容偏移量。如果我慢慢使用我的 tableview,它会工作,但是当我快速拉动时,它会跳出另一个内容,如果条件和我的图像帧没有改变,它不会进入,我想逐步更改这些帧,那又怎样我应该计算它吗?
抱歉我的英语不好:)。感谢您的建议和回答。
scrollViewDidScroll:
不会为偏移量中的每个点变化调用。快速滚动时会跳过一些点。
粗略的解决方案是再添加 2 个条件:
if (scrollView.contentOffset.y <=0)
if (scrollView.contentOffset.y > 60)
将约束设置为您期望从公式中获得的最小值和最大值。
我正在尝试计算我的 scrollViewDidScroll 中的图像帧。当我向下或向上下拉我的 tableview 时,我想更改我的 imageview 框架。
if (scrollView.contentOffset.y > 0 && scrollView.contentOffset.y <= 60) {
userImageViewHeightConstraint.constant = 50 - scrollView.contentOffset.y /6;
userImageViewWidthConstraint.constant = 50 - scrollView.contentOffset.y /6;
userImageView.layer.cornerRadius = userImageViewHeightConstraint.constant/2;
}
我是这样计算的,但是,我习惯于 0 到 60 之间的内容偏移量。如果我慢慢使用我的 tableview,它会工作,但是当我快速拉动时,它会跳出另一个内容,如果条件和我的图像帧没有改变,它不会进入,我想逐步更改这些帧,那又怎样我应该计算它吗?
抱歉我的英语不好:)。感谢您的建议和回答。
scrollViewDidScroll:
不会为偏移量中的每个点变化调用。快速滚动时会跳过一些点。
粗略的解决方案是再添加 2 个条件:
if (scrollView.contentOffset.y <=0)
if (scrollView.contentOffset.y > 60)
将约束设置为您期望从公式中获得的最小值和最大值。