NSScrollview not scrolling

I am attempting to implement an NSScollview for a Mac app. I have created a simple test app. In the IB, I just create a view controller with its view set to an NSScrollview.

In the viewDidLoad, I have just this code:

- (void)viewDidLoad {

[super viewDidLoad];


NSImage * image = [NSImage imageNamed:@"harley-davidson-electra-glide-6"];


NSImageView *imageView = [[NSImageView alloc]initWithFrame:CGRectMake(0, 0, image.size.width, image.size.height)];

imageView.image = image;


[self.scrollView setDocumentView:imageView];

}

Note that the image size is:

(width = 1920, height = 1200)

When I run this I get a window which shows just a small portion of the image. For a half-second, a horizontal scrollbar appears, then disappears; however, there is no scrolling capability. I can click and drag anywhere in the window and nothing happens.

Answered by rschluet in 9245022

OMG, it is user error! I expected that using the mouse to drag thru the document would work to scroll the image. Instead, you just move your finger on the top of the Magic Mouse or use two fingers on the trackpad.

Seems to work ok now.

Never mind...

Did you set the content size for the scroll view?

and then I realize you are on the Mac and not iOS.

That is the problem. I can find a lot of information about the iOS scroll view but not much on NSScrollview.

they have different interfaces.

I think you have to set the content view and not the document view, because it is not an editable document, You just want do display the image, don't you?

the way I understand it is that the clipview is the contentview of the scrollview. Calling [scrollView setDocumentView: imageView] produces a warning. setDocumentView wants an NSClipview.

The NSClipView does have a documentView so I tried:

[self.scrollView.contentView setDocumentView:imageView];

which also doesn't work. The image shows up in the scrollview.

I have examined each of the objects in the debug output window and everything seems right, except no scrolling.

for example:

(lldb) po imageView.frame

(origin = (x = 0, y = 0), size = (width = 1920, height = 1200))

(lldb) po self.scrollView.frame

(origin = (x = 62, y = 52), size = (width = 324, height = 209))

(lldb) po self.scrollView.contentView.frame

(origin = (x = 1, y = 1), size = (width = 322, height = 207))

Accepted Answer

OMG, it is user error! I expected that using the mouse to drag thru the document would work to scroll the image. Instead, you just move your finger on the top of the Magic Mouse or use two fingers on the trackpad.

Seems to work ok now.

Never mind...

NSScrollview not scrolling
 
 
Q