2016-04-15 44 views
0

我在故事板中使用UIScrollview並在其中應用自動佈局。在UIScrollview中,我插入contentview作爲UIScrollview的自動佈局需要一個contentview。現在,根據我的應用場景,我必須更改contentView高度,所以編程方式我已更改contentView的自動佈局。帶自動佈局的UIScrollView SetContentSize

現在我得到contentView的高度= 445以編程方式更改自動佈局後。下面是我的代碼

//----set height of content view----// 
CGRect contentViewFrame = contentView.frame; 
contentViewFrame.size.height= viewMainContent.frame.origin.y+viewMainContent.frame.size.height + 20 ; 
contentView.frame = contentViewFrame; 
_contentHtConstraint.constant = contentView.frame.size.height; 

根據這個UIScrollView的高度也是445。但是UIScrollview的contentSize將是675

有人可以說我如何管理contentSize嗎?

+0

你打電話過'[self updateViewConstraints]'? – zhubch

+0

@zhubch號碼..我必須打電話給我嗎? – Abha

+0

在更改約束後調用它。 – zhubch

回答

0

將高度限制添加到您的內容視圖。併爲它設置出路。 如果您希望視圖控制器啓動時更改內容高度。將其設置在viewWillLayoutSubviews

- (void) viewWillLayoutSubviews{ 
     [super viewWillLayoutSubviews]; 

     //Update your content view height, by updating constant size of height constraint 
     self.contentViewHeightConstraint.constant = 1000;//set this value as per your need. 

     // update your view constraint if needed 
     [self.view updateConstraintsIfNeeded]; 

     //Set content size for your scrollview 
     [self.scrollView setContentSize:CGSizeMake(self.scrollView.contentSize.width, self.contentViewHeightConstraint.constant)]; 

} 
+0

從您的解決方案中,滾動內容大小現在可以管理,但用戶的交互功能已被禁用。我無法在那裏做任何事情。 – Abha

+0

Nilesh ..我沒有使用默認的滾動視圖。在這裏我使用TPKeyboardAvoidingScrollview – Abha

+0

我剛剛在github上檢查了TPKeyboardAvoidingScrollView。它的UIScrollview的子類。您也可以使用TPKeyboardAvoidingScrollView的默認滾動視圖屬性。檢查您的滾動視圖或內容視圖用戶交互是否啓用。或者可能是任何其他視圖重疊您的內容視圖。檢查結構的意見..希望這可能會幫助你 –

相關問題