I'm trying to add a background image in PKCanvasView. I'm able to add the image and view it as long as the contentsize of the PKcanvasView and the content size of the image are identical and that I set the scale factor appropriately.
Once I want to handle zooming in is when things break down. Apparently the
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollViewIs not getting called for some reason. The scrollViewDidEndZooming, on the other hand, is getting called
I'm unsure if this is intended, a bug or i am missing something.
Here is my code to add the image
pencilKitView.delegate = self;
pencilKitView.contentSize = initialImage.size;
pencilKitView.backgroundColor = [UIColor clearColor];
pencilKitView.opaque = NO;
backgroundImageView = [[UIImageView alloc] initWithImage:initialImage];
backgroundImageView.contentMode = UIViewContentModeScaleAspectFit;
[pencilKitView insertSubview:backgroundImageView atIndex:0];
//
pencilKitView.translatesAutoresizingMaskIntoConstraints = false;
[self.view addSubview:pencilKitView];Then I add the constraint to layout the pencilKitView
And my viewDidLayoutSubview
- (void) viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
PKCanvasView *canvasView = ((PKCanvasView*) self.annotationView);
canvasView.contentSize = initialImage.size;
backgroundImageView.frame = CGRectMake(0, 0, canvasView.frame.size.width, canvasView.frame.size.height);
CGFloat canvasScale = canvasView.bounds.size.width / initialImage.size.width;
canvasView.minimumZoomScale = canvasScale;
canvasView.maximumZoomScale = 1;
canvasView.zoomScale = canvasScale;
}