Reputation: 8301
I'm trying to set a scrollview. One way is set scrollview on view but the option is disable. Check screenshot.
Another approach is select all subviews and embebed them on a scrollview but I will loose all my constraints.
Any simple solution to this situation?
Upvotes: 0
Views: 253
Reputation: 5108
view controller
in storyboard
, then go to size inspector
, change the simulated size
to freeform
and set the height
as you need. ex: 1000
.then it will show the actual size. Scroll View
to your Main view
and then add constraints
to is(better to use autolayout
).in here constraints
should be top
,bottom
,leading
,trailing
to you container/main view
.view
to your scrollview
. this is the view
that hold your all other elements. and add constrains
to the this view. constraints
should be top
,bottom
, leading
, trailing
to the scroll view
and height
and width
to the view
itself
.define
a macro
ex: define screenSize [[UIScreen mainScreen] bounds].size
to get the device width. (because at this point when you try to run, it show all good with height and scrolling, except the width.) and create
a IBOutle
to your view
width
, that you added in previous step.final step ----> in you viewDidLoad
method give the constant
value to your view
width
like below.
self.myviewWidthConstraint.constant = screenSize.width;
this will work fine for any device in portrait mode. if anyone wants to make this work in any mode(landscape and portrait) have to identify the mode
change the height
and width
.
note: then add you elements to your view and , add constraints. I think you have to setup all again
for more, refer this link how to setup scroll view for any device, and for any mode in ios.
Upvotes: 0
Reputation: 7903
You cannot embed the Main View
to the Scroll View
, instead you can take a New View
and then Embed into a Scroll View
.
Upvotes: 2