Display content after zooming for UIScrollView

I looked around and it seems that people are saying that you can re-display the data after you zoom in now that you know the scaling factor for the UIScrollView. I also saw some posts on how to make your layer on CATiledLayer and set levelsOfDetailBias and levelsOfDetail.

I have a UIScrollView, and in it is ResultsView, which is a subclass of UIView:

- (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { CATiledLayer *tiledLayer = (CATiledLayer *)self.layer; tiledLayer.levelsOfDetailBias = 3; tiledLayer.levelsOfDetail = 3; self.opaque = YES; } return self; } /* // Only override drawRect: if you perform custom drawing. // An empty implementation adversely affects performance during animation. - (void)drawRect:(CGRect)rect { // Drawing code } */ + (Class)layerClass { return [CATiledLayer class]; } 

In my class, where I have a UIScrollView and ResultsView, I do:

 - (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView { return self.ResultsView; } 

Is this enough for the text to be crossed out (harsh)? Or do I need to implement something in

  - (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx { } 

If so, I'm not sure how to do this. In my class with UIScrollView and ResultsView, in ResultsView (in XIB), I just have several UILabels and UIViews (UIViews are used for headers / footers for presentation). Therefore, I do not know how to redraw them from ResultsView. Although ResultsView has UILabels and UIViews as their children in XIB, I'm not sure how to redraw them from the ResultsView class and what I need to do anyway.

Or is this the wrong approach? Do I just need to resize UILabel and UIView by scale factor in the scrollViewDidEndZooming: delegate method? TIA

+6
source share
2 answers

I think you're wrong. If your view consists of UILabels and UIViews that do not execute any custom drawing, I would not mess up using the supported CATiledLayer view. Instead, we implement the scrollViewDidEndZooming: withView: atScale: delegate method and do something like this:

 - (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale { scale *= [[[self.scrollView window] screen] scale]; [view setContentScaleFactor:scale]; for (UIView *subview in view.subviews) { [subview setContentScaleFactor:scale]; } } 
+18
source

I have something small to add to the decision I made, which caused me several minutes of pain just in case someone else came across the same thing.

Quoting through all the subitems in the view that you scale and invoke setContentScaleFactor does not take into account whether any of the subzones have the subzones themselves. If you have a more complex setup, make sure that you also scroll through the subzones of these container types and call

 [subview setContentScaleFactor:scale]; 

for everybody. I made a method that I can call to call setContentScaleFactor in all subzones of this view and call it for each "container view" on the screen.

 - (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale { scale *= [[[self.scrollView window] screen] scale]; [view setContentScaleFactor:scale]; for (UIView *subview in view.subviews) { [self setContentSizeForView:subview andScore:scale]; //Loop through all the subviews inside the subview for(UIView *subSubview in subview.subviews) { [self setContentSizeForView:subSubview andScale:scale]; } } } - (void) setContentSizeForView:(UIView*) view andScale:(float)scale { [view setContentScaleFactor:scale]; } 
+4
source

Source: https://habr.com/ru/post/898694/


All Articles