Search code examples
iosswiftuiscrollview

Zooming out the table in ScrollView while keeping the frame unchanged


I am using the SwiftDataTables package to represent my tables. That table I pack into another view (aka viewTable), which is in turn added to the scroll view. The idea is to zoom out and see more of the table. Ideally, I would have scrollView.zoomScale = 0.4 as a default value. However, zooming out only results in a smaller rectangle of the view and the table in it.

Basically, what I'm trying to do is very similar to that question/answer, only using scrollView's built-in zooming. Yet, when I use

func scrollViewDidEndZooming(_ scrollView: UIScrollView, with view: UIView?, atScale scale: CGFloat) {...}

it seems to have no influence. I have tried to change

scrollView.contentSize and scrollView.contentOffset; viewTable.frame,viewTable.bounds, anchor.contraint(equalTo: scrollView....) etc.

The view always gets smaller, not filling the scroll view😩

Another thought was to use viewTable.transform, but it seems the constraints are still applied to the unchanged view, thus resulting in the same smaller rectangle


Solution

  • Got it. It was easier to fork the SwiftDataTables and add some functionality (change font) so that the table was "zoomed out" at the beginning with scrollView.zoomScale = 1.