更改 scrollViewDidScroll 中的 UIScrollView 框架会删除顶部的弹跳
Changing UIScrollView frame in scrollViewDidScroll removes bouncing on top
发生了一些奇怪的事情,当我在 UIScrollView 中滚动时,我想将它向上移动并扩展它的高度,因为它在默认情况下太小了。它工作正常,我听了 scrollViewDidScroll 委托,但是它禁用了顶部的弹跳!
即使我在 scrollViewDidScroll 中这样做,顶部弹跳消失了,底部仍然弹跳:
scrollView.frame = CGRectOffset(self.scrollView.frame, 0, 0);
这是我在 scrollViewDidScroll 中的实际代码:
self.maxScrollDistance = 400;
if(scrollView.contentOffset.y <= self.maxScrollDistance) {
float newY = self.startScrollViewY - scrollView.contentOffset.y / 3;
float newScrollViewHeight = self.view.frame.size.height - newY;
scrollView.frame = CGRectMake(0, newY, self.scrollView.frame.size.width, newScrollViewHeight);
}
任何人都可以提示可能是什么问题,一个实际问题的视频:
Bounce Problem Simulator recording
谢谢大家!
滚动到底部时你的框架总是在变化,它不会弹跳,因为在负向滚动时会改变框架contentOffset.y
if(scrollView.contentOffset.y <= self.maxScrollDistance)
尝试在 scrollView 时捕捉。contentOffset.y < 0 并设置其更改框架。
if(scrollView.contentOffset.y < self.maxScrollDistance && scrollView.contentOffset.y>0) {
// Todo
}else if(scrollView.contentOffset.y <= -self.maxScrollDistance && scrollView.contentOffset.y<0){
// Todo
}
// 试试这个代码:
if(scrollView.contentOffset.y < self.maxScrollDistance && scrollView.contentOffset.y>0) {
float newY = self.startScrollViewY - scrollView.contentOffset.y / 3;
float newScrollViewHeight = self.view.frame.size.height - newY;
scrollView.frame = CGRectMake(0, newY, self.scrollView.frame.size.width, newScrollViewHeight);
}else if(scrollView.contentOffset.y <= -self.maxScrollDistance && scrollView.contentOffset.y<0){
float newY = self.startScrollViewY + scrollView.contentOffset.y / 3;
float newScrollViewHeight = self.view.frame.size.height + newY;
scrollView.frame = CGRectMake(0, newY, self.scrollView.frame.size.width, newScrollViewHeight);
}
发生了一些奇怪的事情,当我在 UIScrollView 中滚动时,我想将它向上移动并扩展它的高度,因为它在默认情况下太小了。它工作正常,我听了 scrollViewDidScroll 委托,但是它禁用了顶部的弹跳!
即使我在 scrollViewDidScroll 中这样做,顶部弹跳消失了,底部仍然弹跳:
scrollView.frame = CGRectOffset(self.scrollView.frame, 0, 0);
这是我在 scrollViewDidScroll 中的实际代码:
self.maxScrollDistance = 400;
if(scrollView.contentOffset.y <= self.maxScrollDistance) {
float newY = self.startScrollViewY - scrollView.contentOffset.y / 3;
float newScrollViewHeight = self.view.frame.size.height - newY;
scrollView.frame = CGRectMake(0, newY, self.scrollView.frame.size.width, newScrollViewHeight);
}
任何人都可以提示可能是什么问题,一个实际问题的视频: Bounce Problem Simulator recording
谢谢大家!
滚动到底部时你的框架总是在变化,它不会弹跳,因为在负向滚动时会改变框架contentOffset.y
if(scrollView.contentOffset.y <= self.maxScrollDistance)
尝试在 scrollView 时捕捉。contentOffset.y < 0 并设置其更改框架。
if(scrollView.contentOffset.y < self.maxScrollDistance && scrollView.contentOffset.y>0) {
// Todo
}else if(scrollView.contentOffset.y <= -self.maxScrollDistance && scrollView.contentOffset.y<0){
// Todo
}
// 试试这个代码:
if(scrollView.contentOffset.y < self.maxScrollDistance && scrollView.contentOffset.y>0) {
float newY = self.startScrollViewY - scrollView.contentOffset.y / 3;
float newScrollViewHeight = self.view.frame.size.height - newY;
scrollView.frame = CGRectMake(0, newY, self.scrollView.frame.size.width, newScrollViewHeight);
}else if(scrollView.contentOffset.y <= -self.maxScrollDistance && scrollView.contentOffset.y<0){
float newY = self.startScrollViewY + scrollView.contentOffset.y / 3;
float newScrollViewHeight = self.view.frame.size.height + newY;
scrollView.frame = CGRectMake(0, newY, self.scrollView.frame.size.width, newScrollViewHeight);
}