0

I have a scroll view that has a variable number of UIImageView subviews. I subclassed UIScrollView because I want to be able to move and resize the images with gestures, and do some other custom behavior. As soon as I switch the scroll view to my subclass in the nib file, some strange things happen: the scroll view will expand vertically and cover other views when scrolled upward, and the bottom edge stops short of the full screen and leaves a big gap...but when I change it back to a regular UIScrollView, it's fine. I don't override anything in my subclass or set anything in the nib that I believe could cause this...all I do is override the addSubview method, and add gesture recognizers to subviews as they are added to my scroll view, and of course have methods to handle those gesture recognizers. Any ideas as to what I'm doing wrong?

Thanks in advance!

Reid
  • 1,109
  • 1
  • 12
  • 27
  • I tried to re create the project and could not reproduce the issue. Is it possible to get a sample project? That being said when things start to snap around in unintentional ways my first guess is to look at autolayout. Try turning the autolayout option off for the storyboard or the nib to see if you get the same issue. – datinc Dec 02 '13 at 19:27
  • Don't think I can post any code as it's a company project, under NDA etc. I am narrowing it down, though...when I commented out the whole implementation of my subclass, but still use it (basically, just subclassing in name only) it works normally...so problem must be in my implementation rather than the nib. Just have to start re-adding code until I find the problem :) – Reid Dec 02 '13 at 20:30
  • OK, it is indeed my pan gesture causing the problem...when I re-add that, the scrolling gets funky. It seems that panning *between* the views, which I intend to simply use the scroll view's built-in pan, instead triggers *all* the subviews to pan! There are various ways I can attack this...probably requiring one gesture or the other to fail, or testing that the pan is falling within a subview's bounds (which I didn't think I'd have to do). – Reid Dec 02 '13 at 20:35

1 Answers1

0

Got it! The problem, it seems, was that I had a method called handlePan...by doing this I had inadvertently overridden an identically-named method of UIScrollView. So, my handlePan (which I had intended only to handle the pans for my subviews) was instead handling all pans, including the scrollview's built-in one, and causing the weird scrolling. Whoops! Problem solved.

Reid
  • 1,109
  • 1
  • 12
  • 27