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

具有動(dòng)態(tài)高度的子視圖的自動(dòng)布局 UIScrollView

Auto layout UIScrollView with subviews with dynamic heights(具有動(dòng)態(tài)高度的子視圖的自動(dòng)布局 UIScrollView)
本文介紹了具有動(dòng)態(tài)高度的子視圖的自動(dòng)布局 UIScrollView的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我在使用自動(dòng)布局約束時(shí)遇到了 UIScrollView 的問題.我有以下視圖層次結(jié)構(gòu),通過 IB 設(shè)置約束:

I'm having troubles with UIScrollView using auto layout constraints. I have the following view hierarchy, with constraints set through IB:

- ScrollView (leading, trailing, bottom and top spaces to superview)
-- ContainerView (leading, trailing, bottom and top spaces to superview)
--- ViewA (full width, top of superview)
--- ViewB (full width, below ViewA)
--- Button (full width, below ViewB)

ViewA 和 ViewB 的初始高度為 200 點(diǎn),但可以通過單擊垂直擴(kuò)展至 400 點(diǎn)的高度.ViewA 和 ViewB 通過更新它們的高度約束(從 200 到 400)來擴(kuò)展.這是相應(yīng)的片段:

The ViewA and ViewB have initial heights of 200 points, but it can be expended vertically to an height of 400 points by clicking on it. ViewA and ViewB are expanded by updating their height constraint (from 200 to 400). Here is the corresponding snippet :

if(self.contentVisible) {
    heightConstraint.constant -= ContentHeight;
    // + additional View's internal constraints update to hide additional content 
    self.contentVisible = NO;
} else {
    heightConstraint.constant += ContentHeight;
    // + additional View's internal constraints update to show additional content
    self.contentVisible = YES;
}

[self.view setNeedsUpdateConstraints];
[UIView animateWithDuration:.25f animations:^{
    [self.view layoutIfNeeded];
}];

我的問題是,如果兩個(gè)視圖都展開,我需要能夠滾動(dòng)才能看到整個(gè)內(nèi)容,而現(xiàn)在滾動(dòng)不起作用.如何使用約束來更新滾動(dòng)視圖以反映 ViewA 和 ViewB 高度的變化?

My problem is that if both views are expanded, I need to be able to scroll to see the whole content, and right now the scroll is not working. How can I manage to update the scroll view using constraints to reflect the changes of ViewA and ViewB heights ?

目前我能想到的唯一解決方案是在動(dòng)畫后手動(dòng)設(shè)置ContainerView的高度,這將是ViewA + ViewB + Button的高度之和.但我相信有更好的解決方案?

The only solution I can think of so far is to manually set the height of the ContainerView after the animation, which will be the sum of the heights of ViewA + ViewB + Button. But I believe there is a better solution?

謝謝

推薦答案

我使用如下純結(jié)構(gòu)

-view
  -scrollView
    -view A
    -view B
    -Button

確保 Button(THE LAST view) 有一個(gè)約束(從其底部到父視圖的垂直間距,即滾動(dòng)視圖),在這種情況下,無論您的視圖 A 和視圖發(fā)生什么變化B 是,scrollView 的高度會(huì)相應(yīng)改變.

Make sure Button(THE LAST view) has a constraint(vertical spacing from its bottom to superview, which is the scrollview), in this case, no matter what changes for your view A and view B would be, scrollView's height will be changed accordingly.

我參考了這個(gè)很棒的在線圖書網(wǎng)站.

I reference to this great online book site.

只需閱讀創(chuàng)建滾動(dòng)視圖"部分,您應(yīng)該會(huì)有一個(gè)想法.

Just read the "Creating a scroll view" section, you should have an idea.

我在創(chuàng)建詳細(xì)視圖時(shí)遇到了類似的問題,并且使用具有自動(dòng)布局的 Interface Builder 非常適合該任務(wù)!

I had the similar problem that I was creating a detail view and using Interface Builder with Auto layout is such a good fit for the task!

祝你好運(yùn)!

(其他資源:

關(guān)于滾動(dòng)視圖的自動(dòng)布局的堆棧溢出討論.

iOS 6 有一個(gè)發(fā)行說明 談?wù)搶?duì) UIScrollView 的自動(dòng)布局支持.

iOS 6 has a Release Notes talking about Auto Layout support for UIScrollView.

關(guān)于滾動(dòng)視圖的免費(fèi)在線iOS 書籍說明.這實(shí)際上對(duì)我?guī)椭艽螅?em class="showen">

Free online iOS book explanation about scroll view. This actually helped me a lot!

這篇關(guān)于具有動(dòng)態(tài)高度的子視圖的自動(dòng)布局 UIScrollView的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

How to subclass UIScrollView and make the delegate property private(如何繼承 UIScrollView 并使委托屬性私有)
Swift - how to get last taken 3 photos from photo library?(Swift - 如何從照片庫中獲取最后拍攝的 3 張照片?)
Setting contentOffset programmatically triggers scrollViewDidScroll(以編程方式設(shè)置 contentOffset 觸發(fā) scrollViewDidScroll)
Photos app-like gap between pages in UIScrollView with pagingEnabled(使用 pagingEnabled 的 UIScrollView 中頁面之間的照片應(yīng)用程序式間隙)
why UIScrollView is leaving space from top in ios 6 and ios 7(為什么 UIScrollView 在 ios 6 和 ios 7 中從頂部留下空間)
UIScrollView pauses NSTimer while scrolling(UIScrollView 在滾動(dòng)時(shí)暫停 NSTimer)
主站蜘蛛池模板: 日本三级电影免费观看 | 欧洲成人 | 免费一区 | 久色网 | 国产农村妇女精品一区 | 天天干成人网 | 欧美日韩国产高清视频 | 6080亚洲精品一区二区 | 久久精品中文 | www.黄网 | 射欧美| 97精品视频在线 | 欧美一级免费 | 日本一卡精品视频免费 | 日本精品视频一区二区 | av天天干 | 欧美激情一区二区三区 | 怡红院成人在线视频 | 天天操,夜夜爽 | 一区二区在线免费观看 | 99精品一区二区 | 天天曰天天干 | 黄色免费av | 可以免费观看的av片 | 97国产精品视频人人做人人爱 | 亚洲中午字幕 | 国产精品久久久精品 | 精品国产91 | 欧美一区 | 成人三级视频 | 国产激情视频网 | 久久综合伊人 | 国产极品粉嫩美女呻吟在线看人 | 国产日韩亚洲欧美 | 岛国精品| 久久网国产 | 美女爽到呻吟久久久久 | 在线播放国产一区二区三区 | 亚洲夜夜爽| 欧美日韩成人在线 | www.亚洲精品 |