简体   繁体   English

在scrollViewDidScroll中更改UIScrollView框架可消除顶部的弹跳

[英]Changing UIScrollView frame in scrollViewDidScroll removes bouncing on top

Something strange happening, when I scroll in a UIScrollView I want to move it up and expand it's height because it's too small by default. 发生一些奇怪的事情,当我在UIScrollView中滚动时,我想将其向上移动并扩大其高度,因为默认情况下它太小了。 It works fine and I listen to the scrollViewDidScroll delegate but that disables the bouncing on top! 它工作正常,我听了scrollViewDidScroll委托,但是禁用了顶部的弹跳功能!

Even if I do this in scrollViewDidScroll top bouncing is gone, bottom still bounces: 即使我在scrollViewDidScroll中这样做,顶部的弹跳也消失了,底部仍会弹跳:

scrollView.frame = CGRectOffset(self.scrollView.frame, 0, 0);

This is my actual code in scrollViewDidScroll: 这是我在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);
}

Anyone a hint to what might be the problem, a video of the problem in action: Bounce Problem Simulator recording 任何人都可能会想出什么问题的提示,还有正在发生问题的视频: 弹跳问题模拟器录制

Thanks guys! 多谢你们!

Your frame is always changing when scrolling to bottom, and it's not bouncing because changing frame when scrolling in negative contentOffset.y 滚动到底部时,框架总是在变化,并且不会反弹,因为滚动到负的contentOffset.y时会改变框架。

if(scrollView.contentOffset.y <= self.maxScrollDistance)

Try to catch when scrollView.contentOffset.y < 0 and set its changes frame. 尝试捕获当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
}

// Try this code : //尝试以下代码:

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);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM