1
votes

In general: I got a custom UIView with a xib file as subview on a UIViewController. I add the subview programmatically in my controller.

In my UIViewController:

NSArray *subviewArray = [[NSBundle mainBundle] loadNibNamed:@"MyCustomSubView" owner:self  options:nil];
mySubView = [subviewArray objectAtIndex:0];
...
[self.view addSubview:mapView];

Because I need to scroll on this subview, which also have an UIImageView on it, I decided to change my custom UIView into an UIScrollView.

I did the following steps:

  • Changed the MyCustomSubView.xib, added an UIScrollView with Custom Class MyCustomSubView (and an UIImageView on it like before)
  • Changed my MyCustomSubView class to extend UIScrollView
  • Changed my MyViewController to implement UIScrollViewDelegate
  • set mySubView.delegate to self(the controller)
  • implemented (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView and returned the UIImageView of the subview
  • enabled user interaction on the imageview and on the uiscrollview

These were my total steps I think. But as example, the viewForZoomingInScrollView method wasn't called. Also I tried to zoom in, but nothing happened.

Anyone an idea, what could be wrong?

1

1 Answers

2
votes

Looking briefly at the UIScrollView Class Reference page, I see the following:

The UIScrollView class can have a delegate that must adopt the UIScrollViewDelegate protocol. For zooming and panning to work, the delegate must implement both viewForZoomingInScrollView: and scrollViewDidEndZooming:withView:atScale:; in addition, the maximum (maximumZoomScale) and minimum ( minimumZoomScale) zoom scale must be different.

You mentioned implementing viewForZoomingInScrollView:, but not scrollViewDidEndZooming:atScale:, nor did you mention setting maximumZoomScale or minimumZoomScale. Try doing those things, and check back if you're still having issues.