I'm writing a PDFViewer for a 3rd party PDF library. I have a subclass of NSScrollView and a subclass of NSView. The problem is the NSScrollView will scroll up and down when I resize window.
here is the relevant code:
whenever windows is resized, my subclass of NSScrollView receive this message:
-(void)handleFrameChange:(NSNotification*)notification {
id * docView = [self documentView];
[docView windowResized];
}
in my docView, a subclass of NSView, containing code to draw pdf
- (void)windowResized;
{
NSSize size = [[self superview] bounds].size;
int width = (int) size.width;
int height = (int) size.height;
_pdfView->OnSize(width, height);
double w = _pdfView->GetCanvasWidth();
double h = _pdfView->GetCanvasHeight();
[self setFrameSize:NSMakeSize(w, h)];
//allocate buffer
_buf.resize(width * height * 4, NULL);
[self setNeedsDisplay:YES];
}