简体   繁体   中英

UIScrollView doesn't work

These are my UIViews:

在此处输入图片说明

in my views I have 2 uitableview , 2 button.

I always check my UIView's sizes and these are the results:

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.

But when I divide the height into to 2 (height/2) of the mainview , it allows me to scroll. 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 .

I need to resize the mainview because I need to cover the two(2) uitableview that has sometimes more than 1000height.

_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 will only scroll if its content size is greater than its frame size. 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). Than if the UIScrollView frame height is greater than 25, the UIScrollView will not scroll. Else the UIScrollView will scroll.

hope it helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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