Reputation: 17695
I have this ViewController :
Main View
_-Scroll
__- content view
I need to resize dynamically the content view
I have this method resizeScrollView(), this is my method :
private func resizeScrollView(){
self.mViewContainer.frame.size.height = 800
self.mScrollView.contentSize = self.mViewContainer.frame.size
NSLog("Scroll Height : " + NSNumber(float: Float(self.mScrollView.contentSize.height)).stringValue)
NSLog("Container Height : " + NSNumber(float: Float(self.mViewContainer.frame.height)).stringValue)
}
and i have these logs :
2015-04-21 15:11:44.854 quotle[3673:60b] Scroll Height : 800
2015-04-21 15:11:44.856 quotle[3673:60b] Container Height : 800
At this step, both views are correctly resized.
On my scrolling event, i have link this method :
func scrollViewDidScroll(scrollView: UIScrollView) {
NSLog("Scroll Height : " + NSNumber(float: Float(self.mScrollView.contentSize.height)).stringValue)
NSLog("Container Height : " + NSNumber(float: Float(self.mViewContainer.frame.height)).stringValue)
}
And when i'm scrolling, i see these logs :
2015-04-21 15:11:43.556 quotle[3673:60b] Scroll Height : 800
2015-04-21 15:11:43.559 quotle[3673:60b] Container Height : 416
So, when i am starting to scrolling, my content view is resized...
My question is : What i have to do to keep my content view's height to 800 when i am scrolling and not have this autoresizing of my content view?
You can respond with Obj-C, i'll adapt it to swift.
Upvotes: 0
Views: 1002
Reputation: 61
try this
- (void) fitForScroll:(UIView*) containerViewInScroll :(UIScrollView*)scrollView
{
float w=0;
float h=0;
for (UIView *v in [containerViewInScroll subviews]) {
float fw = v.frame.origin.x + v.frame.size.width;
float fh = v.frame.origin.y + v.frame.size.height;
w = MAX(fw, w);
h = MAX(fh, h);
}
[containerViewInScroll setFrame:CGRectMake(containerViewInScroll.frame.origin.x,containerViewInScroll.frame.origin.y, w, h + 20)];
[scrollView setContentSize:containerViewInScroll.frame.size];
}
----------
Upvotes: 1