2011-11-01 51 views
1

我讀蘋果的樣本代碼在:的NSView變化NSScrollView

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

它的工作原理上的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 

但我更喜歡的NSView改變NSScrollView,我可以看到縮略圖窗外。

但是,如果我從

@interface AssetCollectionView :NSView 

改變代碼

@interface AssetCollectionView :NSScrollView 

AssetCollectionView將無法顯示。

歡迎任何評論

回答

3

NSScrollView自己什麼都不做。這僅僅是一個圍繞另一個NSView的包裝。只需將AssetCollectionView放入NSScrollView即可實現所需的滾動。

要做到這一點:

[[scrollView contentView]addSubview: myView]; 

,將您的視圖添加到滾動視圖的視圖或

[scrollView setContentView:myView]; 

將設置視圖爲滾動視圖的內容視圖。

或者,在Interface Builder中,您可以創建一個滾動視圖並將您的自定義視圖拖入其中。