我正在使用Storyboard
和autolayout
。在我的ViewController
中,我有一個基本結構:一個UIScrollView
和一個包含不同標籤的contentView(UIView
)。然後,我有我的類的viewDidAppear
方法添加我的contentView
裏面,然後以重新計算不同元素的幀尺寸我這樣做:UIView幀未在視圖中更新DIDAppear
- (void)fixContentViewHeight
{
_contentView.frame = CGRectMake(_contentView.frame.origin.x, _contentView.frame.origin.y, _contentView.frame.size.width, operators.frame.origin.y + operators.frame.size.height);
//constraint for contentView height
_contentViewHeight.constant = operators.frame.origin.y + operators.frame.size.height;
}
- (void)fixScrollViewHeight
{
_scrollView.frame = _contentView.frame;
_scrollView.contentSize = _contentView.frame.size;
}
其中operators
是contentView
最後放置的元素,它總是在框架的底部。我將這兩種方法稱爲viewDidAppear
,它們使視圖可滾動,問題在於contentView
的框架沒有更新,因此最後一個元素始終是不可點擊的(因爲它們放置在視圖框架之外)。
我在做什麼錯?爲什麼scrollView
變得可滾動,但contentView
保持它的舊框架?
你使用自動佈局嗎? – Miknash
@NickCatib是的我正在使用自動佈局 – Signo