0

I have a scroll view that has a hidden UIPicker at the bottom which is hidden in viewDidLoad(). This UIPicker is unhidden when a user hits a button. I want my UIScrollview to adjust its height automatically based on whether or not the UIPicker is visible.

However, my scrollview is still trying to take into account the height of the UIPicker and so it goes down further than I would like. I am trying to remedy this by changing the contentSize of the scrollview.

pickerHeight = graphTypePicker.frame.size.height
graphTypePicker.hidden = true
scrollView.contentSize = CGSizeMake(scrollView.contentSize.width, scrollView.contentSize.height - pickerHeight

However, this is not working. Any suggestions? I've tried messing with the frame height before, but that didn't seem to work either.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
dpuleri
  • 96
  • 1
  • 4

1 Answers1

0

The common practice in this case is not to add UIPickerView to your UIScrollView, but add it to your UIViewController's view. To avoid hiding your UIScrollView's content by UIPickerView try to change scroll view's content size on picker appearing. The answers to this question might help you.

Community
  • 1
  • 1
iyuna
  • 1,787
  • 20
  • 24
  • That's not exactly what I would like to do. I don't want to put the UIPickerView inside the popover where the keyboard usually exists. Moreover, if I add the UIPickerView to the UIViewController instead of the UIScollView then it will be outside of the UIStackView that is laying out this whole thing. More similar to what happens at the end of this [youtube video (timestamp 18:55)](https://youtu.be/VWgr_wNtGPM?t=18m55s). Maybe the only way to do it is with a tableview. – dpuleri Feb 09 '16 at 02:50