I have a scroll view with content that is 1000px tall and would like to be able to lay it out for easy design on the storyboard.
I know it can be done programmatically but I really want to be able to see it visually. Every time I put a scroll view on a view controller it won't scroll. Is it possible to get it to work like I want or do I have to do it in the code?
相关问题
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
- Get the NSRange for the visible text after scroll
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- xcode 4 garbage collection removed?
- Xcode: Is there a way to change line spacing (UI L
- Unable to process app at this time due to a genera
- Swift - hide pickerView after value selected
Here are the steps with
Auto Layout
that worked for me on XCode 8.2.1.Size Inspector
ofView Controller
, and changeSimulated Size
toFreeform
with height 1000 instead ofFixed
.View Controller
as RootView.Scroll View
as subview of RootView and rename it as ScrollView.Vertical Stack View
as subview of ScrollView and rename it as ContentView.Attributes Inspector
of ContentView, and changeDistribution
toFill Equally
instead ofFill
.View
as subview of ContentView and rename it as RedView.Red
as the background of RedView.View
as subview of ContentView and rename it as BlueView.Blue
as the background of BlueView.Update Frames
button.Update Frames
is a new button in Xcode8, instead ofResolve Auto Layout Issues
button. It looks like a refresh button, located in the control bar below the Storyboard:View hierarchy:
View Controller Scene (Height: 1000):
Run on iPhone7 (Height: 1334 / 2):
Note that within a
UITableView
, you can actually scroll the tableview by selecting a cell or an element in it and scrolling up or down with your trackpad.For a
UIScrollView
, I like Alex's suggestion, but I would recommend temporarily changing the view controller to freeform, increasing the root view's height, building your UI (steps 1-5), and then changing it back to the standard inferred size when you are done so that you don't have to hard code content sizes in as runtime attributes. If you do that you are opening yourself up to a lot of maintenance issues trying to support both 3.5" and 4" devices, as well as the possibility of increased screen resolutions in the future.Here's a bit of a grubby answer that get's to the same solution for vertical scroll views, but (against the ethos of stackoverflow) doesn't answer the question. Instead of using a scrollView, just use a UITableView, drag a normal UIView into the header, and make it as big as you want, you can now scroll the content in storyboard.
Here is a simple solution.
Set the size attribute of your view controller in the storyboard to "Freeform" and set the size you want. Make sure it's big enough to fit the full content of your scroll view.
Add your scroll view and set the constraints as you normally would. i.e. if you wants the scroll view to be the size of your view, then attach your top, bottom, leading, trailing margins to the superview as you normally would.
Now just make sure there are constraints in the subviews of the scrollview that connect the top and bottom of the scroll view. Same for left and right if you have horizontal scrolling.