IKImageView and scrollbars

I am trying to use the IKImageViewDemo provided by apple ( http://developer.apple.com/mac/library/samplecode/IKImageViewDemo/index.html ) and I am trying to add scrolls to it. I tried two things:

1) embedding IKImageView in ScrollView. It had all kinds of weird effects, for example, the image was no longer where it should have been, and the scroll bars seemed to be in a fixed place, no matter how big the window was (so I could squeeze the window and lose the scroll bars although scrollview was configured to resize the window)

2) I added [_imageView setHasHorizontalScrollers: YES] (and vertically) to the code in the openImageURL method. It didn't seem to do anything.

Am I missing something obvious?

Extras: Why

NSLog(@"scrollbar? H %d V %d hide %d", 
      _imageView.hasHorizontalScroller, 
      _imageView.hasVerticalScroller,
      _imageView.autohidesScrollers);

_imageView.hasHorizontalScroller = YES;
_imageView.hasVerticalScroller = YES;
_imageView.autohidesScrollers = YES;

NSLog(@"scrollbar? H %d V %d hide %d", 
      _imageView.hasHorizontalScroller, 
      _imageView.hasVerticalScroller,
      _imageView.autohidesScrollers);

give me:

scrollbar? H 0 V 0 hide 0
scrollbar? H 0 V 0 hide 0

?

:

, :

 BOOL b = _imageView.autohidesScrollers = YES;
 NSLog (@"b %d scrollers %d", b, _imageView.autohidesScrollers);

print b 1 0?

+3
1

IKImageViewDemo , windowDidResize: ([_imageView zoomImageToFit: self]).

IKImageView NSScrollView - . , ( ) Interface Builder.

: , Mac OS X 10.6 , - . , NSScrollView :

@interface IKImageClipView : NSClipView
- (NSRect)docRect;
@end

@implementation ScrollViewWorkaround

- (void)reflectScrolledClipView:(NSClipView *)cView;
{
    NSView *_imageView = [self documentView];
    [super reflectScrolledClipView:cView];
    if ([_imageView isKindOfClass:[IKImageView class]] &&
         [[self contentView] isKindOfClass:[IKImageClipView class]] &&
         [[self contentView] respondsToSelector:@selector(docRect)]) {
        NSSize docSize = [(IKImageClipView *)[self contentView] docRect].size;
        NSSize scrollViewSize = [self contentSize];
        // NSLog(@"doc %@ scrollView %@", NSStringFromSize(docSize), NSStringFromSize(scrollViewSize));
        if (docSize.height > scrollViewSize.height || docSize.width > scrollViewSize.width)
         ((IKImageView *)_imageView).autohidesScrollers = NO;
        else
         ((IKImageView *)_imageView).autohidesScrollers = YES;
    }
}

@end

:

http://dl.dropbox.com/u/1583683/IKImageViewDemo.zip

IKImageViewDemo .

+8

All Articles