Resizing problem in PDFView sample SOLVED

  • Dear Cocoa-dev People,

    About a year ago, I posted a note on Cocoa-dev asking how to make PDFView (the
    sample application) resize "normally."

    By "normally," I meant that resizing the window should either reveal more of
    the document as the window grew, or clip the bottom of the document as the
    window is shrunk.

    Previously, if you were to drag the bottom-right corner of the window upward,
    shrinking its height, the bottom of the original document remained visible,
    while the document scrolled upward. 

    I probably shouldn't have originally posted this on a Friday night, because
    there were no replies.  So the question remained unsettled UNTIL a recent
    Silicon Valley NSCoder Night.

    Thanks NSCoder Friends!


    The PDFView sample code is here:

    (N.B. This is not related to PDFKit.)

    Add this to PDFImageView.h:

    NSSize clipViewSize;

    And add these methods to PDFImageView.m:

    - (void) awakeFromNib
        NSClipView *clipView = [[self enclosingScrollView] contentView];
        NSParameterAssert(nil != clipView);
        clipViewSize = [clipView frame].size;
        [clipView setPostsFrameChangedNotifications: YES];

        NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
        nc addObserver: self
              selector: @selector(clipViewFrameDidChange:)
                  name: NSViewFrameDidChangeNotification
                object: clipView];

    - (void) clipViewFrameDidChange:(NSNotification *) notification
        NSSize newClipViewSize = [[notification object] frame].size;

        NSPoint scrollPosition = [[notification object] bounds].origin;
        scrollPosition.y = (scrollPosition.y +
                            (clipViewSize.height - newClipViewSize.height));
        [self scrollPoint: scrollPosition];

        clipViewSize = newClipViewSize;

    Get easy, one-click access to your favorites.
    Make Yahoo! your homepage.
previous month november 2007 next month
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30    
Go to today