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

具有動態高度的子視圖的自動布局 UIScrollView

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

問題描述

我在使用自動布局約束時遇到了 UIScrollView 的問題.我有以下視圖層次結構,通過 IB 設置約束:

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 點,但可以通過單擊垂直擴展至 400 點的高度.ViewA 和 ViewB 通過更新它們的高度約束(從 200 到 400)來擴展.這是相應的片段:

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];
}];

我的問題是,如果兩個視圖都展開,我需要能夠滾動才能看到整個內容,而現在滾動不起作用.如何使用約束來更新滾動視圖以反映 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 ?

目前我能想到的唯一解決方案是在動畫后手動設置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?

謝謝

推薦答案

我使用如下純結構

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

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

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.

我參考了這個很棒的在線圖書網站.

I reference to this great online book site.

只需閱讀創建滾動視圖"部分,您應該會有一個想法.

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

我在創建詳細視圖時遇到了類似的問題,并且使用具有自動布局的 Interface Builder 非常適合該任務!

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!

祝你好運!

(其他資源:

關于滾動視圖的自動布局的堆棧溢出討論.

iOS 6 有一個發行說明 談論對 UIScrollView 的自動布局支持.

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

關于滾動視圖的免費在線iOS 書籍說明.這實際上對我幫助很大!

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

這篇關于具有動態高度的子視圖的自動布局 UIScrollView的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

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(以編程方式設置 contentOffset 觸發 scrollViewDidScroll)
Photos app-like gap between pages in UIScrollView with pagingEnabled(使用 pagingEnabled 的 UIScrollView 中頁面之間的照片應用程序式間隙)
why UIScrollView is leaving space from top in ios 6 and ios 7(為什么 UIScrollView 在 ios 6 和 ios 7 中從頂部留下空間)
UIScrollView pauses NSTimer while scrolling(UIScrollView 在滾動時暫停 NSTimer)
主站蜘蛛池模板: 欧美一级www片免费观看 | 亚洲精品视频在线播放 | 一级毛片免费 | 久久在线 | 国产精品久久久久久久久久久久午夜片 | 精品国产99 | 亚洲精品一区二区三区 | 亚洲精品在线免费 | 国产日韩一区二区三区 | 欧美aaa级 | 91精品一区| 91成人影院 | 国产精品久久久久久久粉嫩 | 日韩亚洲一区二区 | 色天堂影院 | 成人高潮片免费视频欧美 | 日本天天操 | 日本一卡精品视频免费 | 久久久久久黄 | 国产精品一区二区久久 | 视频一区二区在线观看 | 午夜精品视频在线观看 | 亚洲一av | 一级特黄视频 | 国产精品1区2区3区 一区中文字幕 | 欧美黑人一区 | 偷牌自拍| 国产精品综合一区二区 | 日韩乱码一二三 | 国产黄色在线观看 | 国产成人免费 | 九九热九九 | 在线一区 | 在线视频一区二区三区 | 亚洲欧美激情视频 | 午夜免费视频 | 亚洲精品久久久久中文字幕欢迎你 | 美女黄18岁以下禁止观看 | 一级片在线免费看 | 久久在线 | 欧美国产精品久久久 |