簡體   English   中英

在Storyboard中創建的容器視圖不會以編程方式更改框架

[英]Container View made in Storyboard will not change frame programmatically

我有一個容器視圖, @property (weak, nonatomic) IBOutlet UIView *containerView; ,但是當我設置它的框架時它不會移動。 以下是我的嘗試方式:

- (void)setFramesForCategories
{
    CGRect frame = _containerView.frame;
    frame.origin.x = 20;
    frame.origin.y = self.view.frame.size.height - 52;
    frame.size.width = 236;
    frame.size.height = 60 * [[_dataDict objectForKey:@"Key"] count];
    _containerView.frame = frame;
}

我知道這是基本的,它之前對我有用,當我以編程方式創建對象時,但它現在對我不起作用。

我遇到的問題是在Storyboard中設置的約束覆蓋了框架更改。 這解釋了為什么我沒有編程添加對象的相同問題。 要關閉項目約束,我只需要轉到Storyboard.storyboard文件,然后確保“Utilities”側欄已打開並選擇“File Inspector”選項卡。 然后我在“Interface Builder Document”下滾動並取消選擇“Use Autolayout”。 在此之后,我重新啟動該項目以找到以編程方式設置框架的工作。

視圖的“框架”屬性用於布局。 如果您在故事板中布置了容器視圖,並想在代碼中移動它。 嘗試“轉換”屬性。 例如,“self.containerView.transform = CGAffineTransformTranslate(self.containerView.transform,0.0,10.0);” =>向上移動容器視圖10分:)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM