This issue has been driving me nuts for the past few hours. So I've got a very simple UIScrollView setup:
-UIScrollView
-UIImageView
That's it. The scrollview and imageview are generated in Storyboard. Now all I want to do is to have the ability to pinch zoom into this image. Minimum zoom is set to 1 and maximum zoom is 3. The scrollview's delegate is set to my RootViewController
In my RootViewController, I have added this function(Required to support zooming)
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{
return _theImageView;
}
I believe I've done everything right but whenever I pinch the scrollview, I get the great EXE_BAD_ACCESS. I've tried to look everywhere and I can't seem to find the issue. Crash dump attached below
0 libobjc.A.dylib 0x34b80f7e objc_msgSend + 22
1 UIKit 0x3516899e -[UIScrollView _getDelegateZoomView] + 70
2 UIKit 0x351908f2 -[UIScrollView _zoomScaleFromPresentationLayer:] + 22
3 UIKit 0x3523bf5a -[UIScrollViewPinchGestureRecognizer touchesBegan:withEvent:] + 102
4 UIKit 0x35102436 -[UIWindow _sendGesturesForEvent:] + 278
5 UIKit 0x351021ee -[UIWindow sendEvent:] + 82
6 UIKit 0x350e868e -[UIApplication sendEvent:] + 350
7 UIKit 0x350e7f34 _UIApplicationHandleEvent + 5820
8 GraphicsServices 0x32c85224 PurpleEventCallback + 876
What am I doing wrong?
Maybe I'm too sleepy
So I solved this the next morning after looking at the code with a fresh pair of eyes. I have a MainViewController
initializing and added RootViewController
to it's subview. The issue was that this was a _weak reference and ARC was dealloc-ing it.
Assigned it as a global _strong variable on MainViewController
and all was fixed.