0

Coming from an iOS background, I presumed that NSScrollView would work out of the box, and I presumed that contentSize would reflect the size of the documentView passed to it. This is not the case, if the NSScrollView is created programmatically.

First issue was: why does contentSize not update when a document view is passed in.

Second issue was: why can I not scroll the scroll view, despite the fact there was more content.

Kalle
  • 13,186
  • 7
  • 61
  • 76
  • 1
    I haven't experienced this myself, but have you tried setting the documentView's frame again after you call setDocumentView: ? – bneely Sep 16 '13 at 19:08
  • I just tried and it's the same deal -- contentSize stays at 1024x150. – Kalle Sep 16 '13 at 19:23
  • Does the documentView have content that is inaccessible by scrolling? Or is the contentSize appropriate for the amount of content currently in the view? – bneely Sep 16 '13 at 19:25
  • There's some content sticking "out" of the bottom ('canvas' class has "isFlipped" set; I tried removing that but it did not affect anything). – Kalle Sep 16 '13 at 19:31
  • Another weirdness is, I get the bounce effect by dragging down (i.e. scroll view scrolls the thing down showing black above) which resets on release, but it doesn't bounce (or move at all) when I try to drag *up*. – Kalle Sep 16 '13 at 19:37
  • I just tried making another scroll view in a clean place and it works, but its contentSize does not reflect the documentView frame, so I am totally off track it seems. – Kalle Sep 16 '13 at 19:42
  • 1
    You are probably using AutoLayouts? Here is a quick article about using ScrollView with autolayouts, its for iOS but applies to OSX too. https://developer.apple.com/library/ios/technotes/tn2154/_index.html – Yas Tabasam Sep 16 '13 at 22:19
  • @Yas Kuraishi: Yes in fact, I am -- I am experimenting with disabling auto layout as I'm not sure how to translate the iOS specifics into Mac specs -- so far it's not making a difference, but I'll continue poking. Thanks for the hint! – Kalle Sep 17 '13 at 10:32

1 Answers1

0

The answer to the first question appears to be: don't look at contentSize, look instead at [[scrollView contentView] documentRect].

The answer to the second is that you have to explicitly set hasVerticalScroller and/or hasHorizontalScroller. The scroll view will then dynamically create NSScroller views.

You can also use setAutohidesScrollers:YES to make those appear only when necessary.

Kalle
  • 13,186
  • 7
  • 61
  • 76