正确的方法UIScrollView上的setContentOffset [英] setContentOffset on UIScrollView the right way

查看:436
本文介绍了正确的方法UIScrollView上的setContentOffset的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用此代码将 UIScrollView 向下滚动,因为我要在其上添加新的 UIView 从底部开始,我想向下滚动到它。我这样做是这样的:

I'm using this code to scroll my UIScrollView down because I'm adding a new UIView on it from the bottom and I want to scroll down to it. I do it like this:

CGPoint newOffset = CGPointMake(mainScrollView.contentOffset.x, mainScrollView.contentOffset.y + floorf(bottomAttachmentView.frame.size.height / bottomAttachmentView.multFactor));
[mainScrollView setContentOffset:newOffset animated:YES];

我基本上将新元素的高度添加到 y UIScrollView contentOffset 的c>,但有时它会滚动到scrollView contentSize ,则可以滚动。发生这种情况是因为我在调用上述方法之前修改了 contentSize ,并且滚动视图的高度缩小了。

I basically add my new element's height to the y of UIScrollView's contentOffset but sometimes it scrolls out of the scrollView contentSize, lower, that it is possible to scroll. It happens because I modify the contentSize before calling the method above and the height of the Scroll View shrinks.

如何调用 setContentOffset ,这样不会使我的scrollView滚动出自己的 contentSize ?谢谢!

How do you call the setContentOffset so it wouldn't make my scrollView scroll out of it's own contentSize? Thanks!

推荐答案

我实际上要做的就是滚动我的 UIScrollView 像这样的底部:

All I had to do actually, was scroll my UIScrollView to the bottom like this:

CGPoint bottomOffset = CGPointMake(0, [mainScrollView contentSize].height - mainScrollView.frame.size.height);
[mainScrollView setContentOffset:bottomOffset animated:YES];

这篇关于正确的方法UIScrollView上的setContentOffset的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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