DrawingFun, NSScrollView and AutoLayout


#1

Hello,

I’ve recently done some learning about Auto Layout and was working through the DrawingFun example in the book. I was able to easily get the basic application without the NSScrollView working with Auto Layout. However when I moved on to embedding the StretchView into the NSScrollView I couldn’t get the content to appear correctly and scroll unless I turned off auto layout and reverted to using the old springs and struts mechanism. I’ve spent a lot of time searching on the web for information around using NSScrollView with auto layout. Is there any information you can provide that walks through getting the scrolling working with Auto Layout enabled? It would be much appreciated.

Thanks,
Rob


#2

In case anyone is as dumb as me (Oh! Right! I’m not dumb – this stuff is just hard!) to turn off autolayout, go to the file inspector for MainMenu.xib; the second section there is “Interface Builder Document”; make sure that’s open; in there look for a checkbox “Use Autolayout”. Uncheck it! Then you can use the springs like in the old days, and the scrolling works fine.

With autolayout on, I didn’t even see a green background on my stretch view. At some points in trying to get it to work (before turning autolayout off) I had bounds size (0,0) for the stretch view, and at some points an NSLog in StretchView’s initWithFrame: wasn’t even called! I’m calling this a bug in the Interface Builder autolayout code (I’m running XCode 5.02 (5A3005)).


#3

I worked on this problem for several days. Went back and watched the videos from the WWDC 2012 , introduction, Best Pratices and Examples for Autolayout.
The went back to the point where you embed the StretchView in a scroll view, from there it was a matter of getting the constraints set for the views.
The working version is posted to github at : github.com/jjraptor/DrawingFun.