問題描述
所以我試圖只在情節提要中創建一個 UIScrollView
,它允許我添加超過 VC 高度的滾動標簽.這是我所做的:
So I'm trying to create a UIScrollView
only in storyboard that allows me to add scrolling labels for more than the height of the VC. Here's what I did:
創建的
UIScrollView
占據任意寬度任意高度VC的大小
Created
UIScrollView
that took up the size of the any width any height VC
在頂部、底部、左側和右側設置了與最近鄰居的間距為 0
Made constraints 0 for spacing to nearest neighbor on top, bottom, left, and right
創建了一個 UIScrollView
的 subView
視圖,其寬度與任意寬度任意高度 VC 相同,但高度為 1500(因為我只想要它垂直滾動).
Created a view that is a subView
of the UIScrollView
with the same width as the any width any height VC but height of 1500 (because I only want it to scroll vertically).
將最近鄰的約束設置為 0,僅用于左側、頂部和右側,并將高度約束設置為 1500.
Set constraints to nearest neighbor as 0 for ONLY left, top, and right and set the height constraint as 1500.
我在subView
的頂部和底部放了一個標簽
I put a label at the top of the subView
and at the bottom
當我在 iPhone 6 上運行該應用程序時,不會像我想要的那樣垂直滾動.任何想法為什么這不起作用?提前致謝.
When I run the app on an iPhone 6, does not scroll vertically as I want it to. Any ideas why this is not working? Thanks in advance.
推薦答案
要獲得滾動,您必須將子視圖(內容視圖")固定到滾動視圖的頂部、左側、底部和右側.此外,您必須給它(給內容視圖")一個明確的(=與滾動視圖無關)高度和寬度,因為滾動視圖使用這些來計算其內容大小.在您的情況下,將寬度設置為 VC 主視圖寬度,將高度設置為 1500.當寬度或高度大于滾動視圖大小時,它將滾動.
To obtain the scroll you have to pin the sub view (the "content view") to the top, left, bottom and right of the scrollview. In addition you have to give it (to the "content view") an explicit (=not related to the scroll view) height and width because these are used by the scrollview to calculate its content size. In your case set the width equal to the VC main view width and the height to 1500. When width or height are bigger than the scrollview size, it will scroll.
滾動視圖約束(固定到主視圖)
Scroll view constraints (pinned to main view)
內容視圖(固定到滾動視圖 + 高度 1500,寬度=主視圖寬度)+ 標簽約束(例如:內容視圖左上角 20 20)
Content view (pinned to scrollview + height 1500, width=mainview width) + label constraints (as an example: 20 20 from content view top left)
這篇關于故事板中的 UIScrollView 不能與 iOS 8 大小類和自動布局一起使用的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!