Properly zooming a UIScrollView that contains many subviews

后端 未结 3 953
死守一世寂寞
死守一世寂寞 2020-12-14 03:05

I created a zoomable UIScrollView and added 100 subviews to it (tiled). The view scrolls perfectly left and right. However, I\'d like to allow zooming.

To do so I re

3条回答
  •  遥遥无期
    2020-12-14 03:25

    Exactly,

    This is what Apple also is mentioning in the Scroll View Programming Guide:

    Just create a view, add all subviews to this view and add the newly created view as a single subview to the scrollview...

    Then in the viewForZoomingInScrollView delegate method return the object at Index 0:

    - (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView 
    {
        return [self.scrollView.subviews objectAtIndex:0];
    }
    

提交回复
热议问题