1
votes

I am reading Apple's sample codes at:

http://developer.apple.com/library/mac/#samplecode/CocoaSlides/Introduction/Intro.html

it works on a NSView

#import <Cocoa/Cocoa.h>

@class Asset;
@class AssetCollection;

// An AssetCollectionView displays the contents of an AssetCollection

@interface AssetCollectionView :NSView
{
    // Model
    AssetCollection *assetCollection;

    // Controller Glue
    NSMutableArray *nodes;

    // Appearance Attributes
    NSGradient *backgroundGradient;

    // UI State
    BOOL autoCyclesLayout;
    NSTimeInterval layoutCycleInterval;
    NSTimer *layoutTimer;
    int subviewsLayoutType;
    NSArray *sortDescriptors;
    BOOL slidesHaveShadows;
    BOOL usesQuartzCompositionBackground;
}

- (AssetCollection *)assetCollection;
- (void)setAssetCollection:(AssetCollection *)newAssetCollection;

- (BOOL)autoCyclesLayout;
- (void)setAutoCyclesLayout:(BOOL)flag;

- (NSTimeInterval)layoutCycleInterval;
- (void)setLayoutCycleInterval:(NSTimeInterval)newLayoutCycleInterval;

- (int)subviewsLayoutType;
- (void)setSubviewsLayoutType:(int)layoutType;

- (NSArray *)sortDescriptors;
- (void)setSortDescriptors:(NSArray *)newSortDescriptors;

- (BOOL)slidesHaveShadows;
- (void)setSlidesHaveShadows:(BOOL)flag;

- (BOOL)usesQuartzCompositionBackground;
- (void)setUsesQuartzCompositionBackground:(BOOL)flag;

- (void)reloadData;
@end

but I prefer to change NSView to NSScrollView that I can see the thumbnail outside the window.

But if I change the codes from

@interface AssetCollectionView :NSView

to

   @interface AssetCollectionView :NSScrollView

AssetCollectionView will display nothing.

Welcome any comment

1

1 Answers

3
votes

An NSScrollView does nothing on its own. It is merely a wrapper around another NSView. Simply put your AssetCollectionView inside an NSScrollView to achieve the desired scrolling.

To do this use:

[[scrollView contentView]addSubview: myView];

which will add your view to the scroll view's view, or

[scrollView setContentView:myView];

which will set your view as the scroll view's content view.

Or, in Interface Builder, you can create a scroll view and drag your custom view into it.