IOS自動布局與非自動布局嵌套使用的解決辦法

來源:互聯網
上載者:User

標籤:

/*關於autolayout多說幾句
         *   在一個控制項記憶體在autolayout與autoresize子控制項時,要適配部分autoresize
         *   translatesAutoresizingMaskIntoConstraints 預設是開啟轉換的
         //在autoresize下可以通過以下代碼進行autolayout視圖的大小計算
         if (!contentView.translatesAutoresizingMaskIntoConstraints) {
         [contentView needsUpdateConstraints];
         [contentView updateConstraints];
         CGSize ss = [contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize];

         }
         //另外如果autolayout視圖在autoresize視圖內部,而且需要配置相對位置,可以通過以下代碼設定
         [autoresizeView removeConstraints:autoresizeView.constraints];//或者只刪除配置內容相關的

         NSDictionary *dic = NSDictionaryOfVariableBindings(autolayout);
         NSString *VFL = [NSString stringWithFormat:@"V:|-%f-[autolayout]",rect.origin.y];
         NSArray *ar = [NSLayoutConstraint constraintsWithVisualFormat:VFL options:0 metrics:nil views:dic];
         [autoresizeView addConstraints:ar];

         VFL = [NSString stringWithFormat:@"|-%f-[autolayout]",rect.origin.x];
         ar = [NSLayoutConstraint constraintsWithVisualFormat:VFL options:0 metrics:nil views:dic];

         [autoresizeView addConstraints:ar];
         */


還有一種辦法在外面進行計算,給autolayout的視圖加個UIView殼,systemLayoutSizeFittingSize:計算出大小設定到殼上,再放到非autolayout支援的視圖上

IOS自動布局與非自動布局嵌套使用的解決辦法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.