I have an extended UIScrollView that is taken directly from the Apple documentation example project "ZoomingPDFViewer"
If you get this project you'll note that it's UIScrollView extension class "PDFScrollView" has a glaring bug when you run it (on sim AND device)
If you pinch zoom far enough, you'll eventually hit the zoom scale limits set by the StoryBoard... but then, you can just re-pinch and go right on past the limits.
I've been trying to implement this class in my own project, and this bug has come with it.
For some reason, after the zoom ends, the zoomScale property of the UIScrollView is being arbitrarily set back to 1.0, so you can effectively pinch zoom to infinity... keep in mind the zoomScale being reset does NOT impact the content... so you can just keep zooming out until the PDF in the demo is just a pixel on the screen.
I've never seen this before and I've done tons of custom UIScrollViews before.
I've tried a few steps to solve it but nothing seems to be working. Does anyone know what would cause a UIScrollView to reset its zoomScale in that manner?
I thought it might be because the subviews are being removed and added during zooms, but I put a dummy view in the scroll view to act as an anchor, and that did not work either.
Like I said.. ZoomingPDFViewer is the exact code I am working with, using iOS 6.0
Any ideas would be appreciated. Sample code below
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale
{
NSLog(@"Ending Zoom %0.2f %0.2f", [self zoomScale], scale);
// Set the new scale factor for the TiledPDFView.
_PDFScale *= scale;
// Calculate the new frame for the new TiledPDFView.
CGRect pageRect = CGPDFPageGetBoxRect(_PDFPage, kCGPDFMediaBox);
pageRect.size = CGSizeMake(pageRect.size.width*_PDFScale, pageRect.size.height*_PDFScale);
// Create a new TiledPDFView based on new frame and scaling.
TiledPDFView *tiledPDFView = [[TiledPDFView alloc] initWithFrame:pageRect scale:_PDFScale];
[tiledPDFView setPage:_PDFPage];
// Add the new TiledPDFView to the PDFScrollView.
[self addSubview:tiledPDFView];
self.tiledPDFView = tiledPDFView;
NSLog(@"End of end zoom %0.2f", [self zoomScale]);
}
This is the end scroll delegate... both of this logs produce a zoomScale that is exactly what you would expect... so... any number other than 1.0, assuming you actually zoomed.
Then layoutSubviews is called..
// Use layoutSubviews to center the PDF page in the view.
- (void)layoutSubviews
{
[super layoutSubviews];
// Center the image as it becomes smaller than the size of the screen.
CGSize boundsSize = self.bounds.size;
CGRect frameToCenter = self.tiledPDFView.frame;
// a bunch of code that sets frameToCenter
self.tiledPDFView.frame = frameToCenter;
self.backgroundImageView.frame = frameToCenter;
/*
To handle the interaction between CATiledLayer and high resolution screens, set the tiling view's contentScaleFactor to 1.0.
If this step were omitted, the content scale factor would be 2.0 on high resolution screens, which would cause the CATiledLayer to ask for tiles of the wrong scale.
*/
self.tiledPDFView.contentScaleFactor = 1.0;
NSLog(@"Subviews Layed Out %0.2f", [self zoomScale]);
}
At this point, zoomScale reports back as 1.0 no matter what... this traces 0.003 seconds after the End Zoom delegate method reports a proper zoom scale.