Reputation: 1066
No matter what content size of UITableView
, it can always scroll. but now I want UIScrollView
also like it.....
At first, I use the code like this:
self.scrollView.contentSize = CGSizeMake(0, self.view.frame.size.height - 63);
It does work, but now I use AutoLayout, it said I must certain a content size.
the app have to adapt to iPhone4~iPhone 6 Plus, so the content size can't be certain, it always small than screen subtract 1, just like this (because the state bar and the navigation bar take over 64 px)
self.scrollView.contentSize = CGSizeMake(0, self.view.frame.size.height - 63);
BTW, if I don't certain a size, and write this code in - (void)viewDidLoad
,while Xcode compile it just a warming, don't affect the APP running.
I hope you can give me some better way.
Upvotes: 0
Views: 485
Reputation: 1066
I have solve this issue, just add this scrollView.alwaysBounceVertical = YES
, then I can scroll the ScrollView no matter if the content beyond the frame
Upvotes: 2
Reputation: 10175
First of all, I barely understand what you want.
Now the technical part:
It's not a good practice, hell, you should never change the content size of a UITableView
, UITableView
always compute his content size based on heightFirRowAtIndexPath
, heightForHeader...
and the other heightFor...
methods, that's why the table will scroll (of course if the methods are implemented right)
The UIScrollview
won't compute the content size by itself because it's not designed that way, so you'll have to specify the content size for it. Usually when a UIScrollView
doesn't scroll it's because the contentSize
it's smaller than the scroll's frame size so it doesn't have to scroll.
Implementing a UIScrollView
with auto-layout it's a little tricky and you have to do some tweaks, but Apple provides a some examples here how you should do it. Also a little googling will find a ton of examples on how to do it.
Upvotes: 0