久久久久久久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)
主站蜘蛛池模板: 欧美日韩大片 | 日韩在线视频一区 | 国精品一区 | 国产久 | 91在线播 | 在线视频一区二区三区 | 亚洲不卡av在线 | 久久神马| 日韩电影免费观看中文字幕 | 国产人成精品一区二区三 | 日韩人体视频 | 影音先锋欧美资源 | 精品国产第一区二区三区 | 国产女人与拘做受视频 | 欧美一区二区三区 | 久久精品99久久 | 国产一二三视频在线观看 | 欧美日韩中文字幕在线 | 欧美mv日韩mv国产网站91进入 | 91中文字幕在线观看 | 最新国产视频 | 日韩成人免费av | 国产精品一区免费 | 国产精品1区2区3区 中文字幕一区二区三区四区 | 精品综合 | 色综合久久天天综合网 | 日韩中文字幕一区 | 精品国产欧美一区二区三区成人 | 亚洲精品九九 | 成人h视频在线 | 97精品一区二区 | 国产精品免费看 | 免费国产一区二区视频 | 国产欧美一区二区三区国产幕精品 | 欧美中文字幕 | 日韩精品一区二区三区老鸭窝 | 国产精品99久久久久久久久久久久 | 国产精品视频一二三区 | 午夜成人免费视频 | 亚洲精品9999| 欧美日韩综合视频 |