简体   繁体   English

UIScrollView不起作用

[英]UIScrollView doesn't work

These are my UIViews: 这些是我的UIViews:

在此处输入图片说明

in my views I have 2 uitableview , 2 button. 在我看来,我有2 uitableview ,2按钮。

I always check my UIView's sizes and these are the results: 我总是检查我的UIView的大小,这些是结果:

randomPOC[2231:67151] MainView-1060.000000
2018-05-17 10:33:28.812877+0800 randomPOC[2231:67151] ScrollView-1060.000000
2018-05-17 10:33:28.813094+0800 randomPOC[2231:67151] ContentView-1060.000000

When my mainview , scroll and contentview have the same sizes, it doesn't scroll. 当我的mainviewscrollcontentview具有相同的大小时,它不会滚动。

But when I divide the height into to 2 (height/2) of the mainview , it allows me to scroll. 但是,当我将高度划分为mainview 2(height / 2)时,它允许我滚动。 which makes me confused how and why. 这让我感到困惑。

when I divided the mainview height into to 2 it allows me to scroll but it doesn't covers down to the last of the tableview . 当我将mainview高度分为2时,它允许我滚动,但是它并没有覆盖到tableview的最后一个。

I need to resize the mainview because I need to cover the two(2) uitableview that has sometimes more than 1000height. 我需要调整mainview大小,因为我需要覆盖有时超过1000高度的two(2) uitableview

_mainView.frame=CGRectMake(_mainView.frame.origin.x, _mainView.frame.origin.y, _mainView.frame.size.width, uitableview2.height  );

通过使用如下调整主视图大小的方法找到了答案:

_mainView.frame=CGRectMake(_mainView.frame.origin.x, _mainView.frame.origin.y, _mainView.frame.size.width, [[UIScreen mainScreen]bounds].size.height );

This answer has nothing to do with why your UIScrollView doesnt work. 这个答案与UIScrollView为什么不起作用无关。 UIScrollView will only scroll if its content size is greater than its frame size. UIScrollView仅在其内容大小大于其框架大小时才滚动。 You should first decide the size of your UIScrollView frame, Than for a Veritical UIScrollView you should assign the content size as follow: Lets say you have 5 UIView's which have height of 5 dp each, than you should set the UIScrollView height like so: scrollview.setContentSize(width, 5*5). 首先,您应该确定UIScrollView框架的大小,然后再为Veritical UIScrollView分配内容大小,如下所示:假设您有5个UIView,每个高度为5 dp,而不是像这样设置UIScrollView高度: .setContentSize(width,5 * 5)。 Than if the UIScrollView frame height is greater than 25, the UIScrollView will not scroll. 如果UIScrollView的框架高度大于25,则UIScrollView不会滚动。 Else the UIScrollView will scroll. 否则,UIScrollView将滚动。

hope it helps! 希望能帮助到你!

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

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