ios resize scrollview by containerview with tavleview inside

ios swift uiscrollview size uicontainerview

502 观看


26 作者的声誉

I have next structure of views:

--safe area
-----tableviewcontroller(in containervew3)

Tableviewcontroller has buttons which add or remove rows, I want to resize scroll view that it shows full tableview content(without scrolling in tableview). I tried to solution like: from here or Sizing a Container View with a controller of dynamic size inside a scrollview but without success. I use iOS 10.0&swift

作者: Anton Lisitsyn 的来源 发布者: 2017 年 12 月 27 日

回应 (1)


9501 作者的声誉

First thing is constraints. You must have proper constraints with UIScrollView and container's view

Next thing you need is height constraints of tableviewController (you can give height to 0 with relation greater than equal with 750 priority so constrains would never break if something wrong happened)

Take IBOutlet of that height constraint when your data insert / delete happen your content size will change and apply that contentsize height to constant of IBOutlet constraint and don't forgot to layoutIfNeeded.

Make your tableview scrolling bounce to false

create protocol to notify container view about height change

protocol ContainerTableDelegate {
      func dataChanged(height: CGFloat)

and when height change notify parent view controller


Now in the main viewcontroller where you have all containers


 override func prepare(for segue: UIStoryboardSegue, sender: Any?) 

identify ViewController set delegate to self implement delegate and change height of container view 3 constant (You also need this)

Hope it will help to solve your issue

作者: Prashant Tukadiya 发布者: 28.12.2017 04:54