久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

在滾動(dòng)視圖中使用動(dòng)態(tài)大小的控制器調(diào)整容器視

Sizing a Container View with a controller of dynamic size inside a scrollview(在滾動(dòng)視圖中使用動(dòng)態(tài)大小的控制器調(diào)整容器視圖的大小)
本文介紹了在滾動(dòng)視圖中使用動(dòng)態(tài)大小的控制器調(diào)整容器視圖的大小的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我正在嘗試在 UIScrollView 內(nèi)創(chuàng)建一個(gè)具有動(dòng)態(tài)高度的控制器的容器視圖,并使用自動(dòng)布局自動(dòng)調(diào)整其大小.

I'm trying to create a container view, with a controller that has a dynamic height, inside a UIScrollView and have it sized automatically using auto layout.

View Controller A 是滾動(dòng)視圖,其中包含容器視圖,以及下面的更多內(nèi)容.

View Controller A is the scrollview, which has the container view included, along with more content below.

視圖控制器 B 是視圖控制器,我希望它具有動(dòng)態(tài)大小,并且所有內(nèi)容都在視圖控制器 A 的滾動(dòng)視圖中以全高顯示.

View Controller B is the view controller that I want to have a dynamic size and for all the content to be displayed in full height in View Controller A's Scroll View.

我在獲取 B 的動(dòng)態(tài)大小以自動(dòng)設(shè)置 A 中的容器視圖的大小時(shí)遇到??一些問題.但是,如果我在 A 中的容器視圖上設(shè)置高度限制 ,

I'm having some problems getting the dynamic size of B to automatically set the size of the Container View in A. However if I set a height constraint on the Container View in A ,

如果視圖控制器 B 的高度也為 250,這將是預(yù)期的輸出.它也適用于高度 1000,據(jù)我所知,所有自動(dòng)布局約束都已正確設(shè)置.不幸的是,由于高度實(shí)際上應(yīng)該是動(dòng)態(tài)的,所以我想完全避免設(shè)置高度約束.

It would be the expected output if View Controller B would also have 250 height. It also works fine for height 1000, so as far as I know, all the auto layout constraints are properly setup. Unfortunately, since the height should actually be dynamic, I would like to avoid setting a height constraint at all.

我不確定視圖控制器 B 是否有任何設(shè)置,我可以設(shè)置它以根據(jù)其內(nèi)容自動(dòng)更新其大小,或者我是否錯(cuò)過了任何其他技巧.任何幫助將不勝感激!

I'm not sure if there are any settings for view controller B I can set for it to automatically update its size depending on its contents, or if there are any other tricks I've missed. Any help would be much appreciated!

有沒有什么辦法可以在不設(shè)置高度限制的情況下,根據(jù) View Controller B 的大小來調(diào)整 A 中的 Container View 的大小?

Is there any way to size the Container View in A according to how big the size of View Controller B is without setting a height constraint?

推薦答案

是的,有.我設(shè)法在自己的一個(gè)項(xiàng)目中實(shí)現(xiàn)了這種行為.

Yup, there is. I managed to achieve that kind of behavior in one of my own projects.

您所要做的就是告訴系統(tǒng)它不應(yīng)該添加模仿在 Interface Builder 中為您的根視圖設(shè)置的固定框架的約束.當(dāng)您的嵌入 segue 被觸發(fā)時(shí),執(zhí)行此操作的最佳位置是在您的容器視圖控制器中:

All you gotta do is to tell the system that it should not add constraints that mimic the fixed frame set for your root view in Interface Builder. The best place to do this is in your container view controller when your embed segue is triggered:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // You might want to check if this is your embed segue here
    // in case there are other segues triggered from this view controller. 
    segue.destinationViewController.view.translatesAutoresizingMaskIntoConstraints = NO;
}

重要:

您必須確保加載到容器中的視圖從上到下受到約束,并且您需要將其中一個(gè)垂直約束的優(yōu)先級(jí)設(shè)置為低于 1000 的值.(始終使用底部約束.)這是必要的,因?yàn)榉駝t Interface Builder 會(huì)抱怨 - 有一個(gè)很好的理由:

Important:

You gotta make sure that the view that you load into the container is constrained from top to bottom and you need to set the priority of one of the vertical constraints to a value lower than 1000. (It's a good practice to always use the bottom constraint for this.) This is necessary because otherwise Interface Builder will complain — with a good reason:

在設(shè)計(jì)時(shí),您的根視圖具有固定的大小(高度).現(xiàn)在,如果您的所有子視圖都具有固定高度并與所有具有相同優(yōu)先級(jí)的固定約束連接,則不可能滿足所有這些要求,除非您的固定根視圖的高度恰好與子視圖的總高度和垂直約束完全匹配.如果您將其中一個(gè)約束的優(yōu)先級(jí)降低到 999,Interface Builder 就會(huì)知道要打破哪個(gè)約束.然而,在運(yùn)行時(shí)——當(dāng) translatesAutoresizingMaskIntoConstraints 屬性按上述設(shè)置時(shí)——你的根視圖不再有固定的框架,系統(tǒng)將使用你的 999 優(yōu)先級(jí)約束.

At design time your root view has a fixed size (height). Now if all your subviews have a fixed height and are connected with fixed constraints that all have the same priority it's impossible to fulfil all these requirements unless the height of your fixed root view coincidentally matches exactly the total height of your subviews and the vertical constraints. If you lower the priority of one of the constraints to 999 Interface Builder knows which constraint to break. At runtime however — when the translatesAutoresizingMaskIntoConstraints property is set as stated above — there is no fixed frame for your root view anymore and the system will use your 999 priority constraint instead.

這篇關(guān)于在滾動(dòng)視圖中使用動(dòng)態(tài)大小的控制器調(diào)整容器視圖的大小的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

iOS - Using storyboard and autolayout to center the UIScrollView(iOS - 使用故事板和自動(dòng)布局使 UIScrollView 居中)
get index or tag value from imageview tap gesture(從 imageview 點(diǎn)擊手勢(shì)獲取索引或標(biāo)簽值)
UIScrollView not scrolling regardless of large contentSize(無論內(nèi)容大小如何,UIScrollView 都不會(huì)滾動(dòng))
Clean autorotation transitions in a paging UIScrollView(清除分頁 UIScrollView 中的自動(dòng)旋轉(zhuǎn)轉(zhuǎn)換)
UIScrollView zooming with Auto Layout(UIScrollView 使用自動(dòng)布局縮放)
How to create an image from a UIView / UIScrollView(如何從 UIView/UIScrollView 創(chuàng)建圖像)
主站蜘蛛池模板: 97精品超碰一区二区三区 | 精品久久久久国产 | 国产精品久久国产精品 | 国产精品成人一区二区三区夜夜夜 | 欧美一区二区激情三区 | 999久久久久久久久6666 | 国产精品日韩在线 | 成人影视网址 | 国产精品成人免费 | 草草视频在线观看 | 国产欧美在线一区 | 在线观看中文字幕视频 | 免费视频一区 | 国产精品99一区二区 | 91免费视频 | 九九久久精品 | 久草a√| 亚洲成人一区 | 四季久久免费一区二区三区四区 | 欧美bondage紧缚视频 | 天堂成人国产精品一区 | 911精品美国片911久久久 | 99久久免费精品视频 | 亚洲逼院| 日韩影院在线观看 | 在线视频一区二区 | 成人免费毛片在线观看 | 日韩国产免费观看 | 一区久久| 国产亚洲精品综合一区 | av夜夜操 | 久久99精品久久久久蜜桃tv | 国产 日韩 欧美 在线 | 91精品一区二区三区久久久久久 | 亚洲网站在线观看 | 国产一二三视频在线观看 | 国产在线麻豆精品入口 | 国产成人精品久久二区二区91 | 欧美日韩国产中文字幕 | 99久久久久久99国产精品免 | 天天躁日日躁xxxxaaaa |