0

I have a view controller with a UIScrollView. Inside that scrollview I have two UIViews. viewA sits onto of viewB. I am using Xcode 5 and auto layout in this project. What I would like to do is when viewA is hidden, move viewB to the top where viewA was sitting (technically, still sitting, just hidden).

I looked at this SO answer: How to use auto-layout to move other views when a view is hidden?

However it hasn't really helped me. I connected a IBOutlet which was a constant to the vertical spacing to the top of the scroll view and set it to 0.0f when viewA was hidden. However it makes no changes to my UI at all.

Community
  • 1
  • 1
Robert J. Clegg
  • 7,231
  • 9
  • 47
  • 99
  • can you post the code where you are changing the value of vertical spacing ? and to which element this vertical spacing is with ? – Suhaiyl Mar 03 '14 at 11:48

1 Answers1

2

First get the Top Space to SuperView NSlayoutConstraints Outlets for both subViews and then do the following:-

[self.aView setHidden:YES];
if([self.aView isHidden])
{
    self.bViewTopConstraint.constant = self.aViewTopConstraint.constant;
}

using this the second UiView will go to the place of first UIView.

For Scrollview you have to set the constraints value properly. No need to set any contentsize. Once you set the constriants scrollview will work automatically. Check the attached screenshot.

enter image description here

Sushil Kumar
  • 130
  • 7
  • Thanks. This gets me on the right track. However my scrollView no longer works. As my understanding goes - setting the contentSize of a UIScrollView no longer applies when using AutoLayout. So what should I do to get it to scroll? – Robert J. Clegg Mar 03 '14 at 12:26