ios resize scrollview by containerview with tavleview inside

ios swift uiscrollview size uicontainerview

502 观看

1回复

26 作者的声誉

I have next structure of views:

vc
-view
--safe area
--scrollview
---view
----containerview1
----containerview2
----containerview3
-----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


0

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

    delegate?.dataChanged(self.heightConstraint.constant)

Now in the main viewcontroller where you have all containers

implement

 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 发布者: 2017 年 12 月 28 日
32x32