简体   繁体   中英

Zoom in/out of a whole Tableview

Problem: I got a Tableview with dynamically many cells. The cells contain PKDrawings with the PencilKit Framework. So its like a book...

I would like to do 2 things: 1. Zoom in so i am closer to the cells-content so the drawings seem bigger. (But when I say cells-content I mean all cells so I am talking about the Tableview. I don't want to zoom into a specific cell)

2. Zoom out so I start seeing more and more pages (cells) above and below the one that was "in my focus" when not zooming out or in. If that's not possible as the Cells are Hidden and its hard to tell them while zooming out when to load again its fine if the maximal zoom-out is the point when I haven't zoomed in.

As a Tableview is already a subclass of the UIScrollview I can access its min & max Zoomscale. However setting this doesn't change anything. The ScrollViewDidZoom won't get triggered either. Scrolling works fine though...

I think that this should all be possible if I somehow manage it to put my Tableview into another View/Scrollview and just zoom in/out on that but I don't know how to do that...

Thanks in advance for any help!

For zooming UITableview cell u can use CGAffineTransform. You can manage the scale value as per requirement

    // For Zoom  in 
    CGAffineTransform trans = CGAffineTransformScale(cell.contentView.transform, 100, 100);
    view.transform = trans;

    // For Zoom Out
    CGAffineTransform trans = CGAffineTransformScale(cell.contentView.transform, 0.01, 0.01);
    view.transform = trans;

To zoom complete UItableView you can apply affine transform to tableview

    // For Zoom  in 
    CGAffineTransform trans = CGAffineTransformScale(tableView.transform, 100, 100);
    view.transform = trans;

    // For Zoom Out
    CGAffineTransform trans = CGAffineTransformScale(tableView.transform, 0.01, 0.01);
    view.transform = trans;

For pinch gesture u can use following gestures well documented by apple developer documentation https://developer.apple.com/documentation/uikit/touches_presses_and_gestures/handling_uikit_gestures/handling_pinch_gestures

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM