I'm resizing my scroll view's content size programmatically. To do this, I look through all of the views contained within it and get the highest value for the view origin plus the view height, then set my content size to that plus 10. For some reason, I have a lot of white space at the bottom of my page. I used an NSLog()
to find out what object it thought was this big and found that it is an object that does not even exist. Here is my code:
- (void)resize_scrollview_to_fit {
CGFloat scrollViewHeight = 0.0f;
for (UIView *view in scrollView.subviews) {
if (view.frame.size.height + view.frame.origin.y > scrollViewHeight) {
scrollViewHeight = view.frame.size.height + view.frame.origin.y + 10;
NSLog(@"Scroll View Height: %f \nView Type: %@", scrollViewHeight, view.class);
}
}
[scrollView setContentSize:(CGSizeMake(scrollView.frame.size.width, scrollViewHeight))];
}
The output is:
2014-05-16 10:40:56.757 eTicket[5542:907] Scroll View Height: 175.000000
View Type: UIImageView
2014-05-16 10:40:56.767 eTicket[5542:907] Scroll View Height: 301.000000
View Type: UILabel
2014-05-16 10:40:56.773 eTicket[5542:907] Scroll View Height: 345.000000
View Type: UITextField
2014-05-16 10:40:56.780 eTicket[5542:907] Scroll View Height: 399.000000
View Type: UILabel
2014-05-16 10:40:56.787 eTicket[5542:907] Scroll View Height: 441.000000
View Type: UILabel
2014-05-16 10:40:56.794 eTicket[5542:907] Scroll View Height: 520.000000
View Type: UIImageView
There is only one UIImageView on this page within the scroll view, which is the first item listed. That second UIImageView does not exist in either code or the storyboard. The above code should end with the result of 441. I have no code creating an UIImageView, and the only other 2 UIImageViews in the storyboard are on the same level as the UIScrollView and not within it. Plus they would result in given 558 if it was seeing them. So where is this extra UIImageView coming from, and how do I get rid of it?
Thanks, James
EDIT
Are there really no other solutions for this? I'd hate for Sasha's answer to be the only way to resolve this. It just doesn't seem logical that a UIImageView would just be added automatically to a UIScrollView. If his answer is correct though, can someone confirm it?
Thanks, James