停止滚动滚动视图中的最后一个对象 [英] Stop scrolling at last object in Scroll View

查看:29
本文介绍了停止滚动滚动视图中的最后一个对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如您在附加图像中看到的那样,如果我继续滚动滚动视图中的最后一个对象,我可以继续滚动然后看到背景.有没有办法在 xcode 中限制这个,这样你就不能滚动过去滚动视图中的最后一个对象?

As you can see in the attached image if I keep scrolling past the last object in my scrollview I can keep scrolling and then see the background. Is there a way to limit this in xcode so you can't scroll past the last object in the scroll view?

我是 xcode 的新手,确实尝试过研究这个问题,但我相信我的术语会影响到这一点.

I'm new to xcode and did try researching this issue though I believe my terminology is impacting this.

谢谢

推荐答案

您需要设置 scrollView.contentSize 大小,使其适合滚动视图中的所有对象.如果您有办法确定哪个对象最低,那么您可以使用其原点 + 高度来确定内容大小的高度.

you will need to set the scrollView.contentSize size so that it fits around all your objects in the scroll view. if you have a way to determine which object is the lowest then you can use its origin + height to determine the height of the content size.

float maxHeight = 0;

for(UIView *v in [scrollView subviews]){
    if(v.frame.origin.x + v.frame.size.height > maxHeight)
        maxHeight = v.frame.origin.x + v.frame.size.height;
}

self.scrollView.contentSize = CGSizeMake(scrollView.frame.size.width, maxHeight+5);

这篇关于停止滚动滚动视图中的最后一个对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆