Ricardo
Ricardo

Reputation: 8301

iOS - Storyboard - cannot view embed in scrollView

I'm trying to set a scrollview. One way is set scrollview on view but the option is disable. Check screenshot.

enter image description here enter image description here

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

Answers (2)

caldera.sac
caldera.sac

Reputation: 5108

  • Step one ---> Select your 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.
  • step two ----> add 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.
  • step three ---> then add another 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.
  • then 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

Bista
Bista

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

Related Questions