如何让 NSCollectionView 在包含 NSCollectionView 的视图可见之前完成绘制?

StackOverflow https://stackoverflow.com/questions/3060238

  •  28-09-2019
  •  | 
  •  

我正在尝试清理我的应用程序上的 UI(为 10.5 构建),一件相当烦人的事情是,当我交换到库时,我重新加载内容,并且显示项目的 nscollectionview 在淡出旧内容之前淡出旧内容新的在.我不介意旧/新项目的淡入/淡出,但我编程视图交换的方式应该使库重新加载发生在包含 nscollectionview 的 nsview 插入主窗口之前。

以前有人遇到过这样的问题吗?

以下是应用程序的不同部分与库之间的交换如何进行的简化版本:

在主控制器中:

-(void)setMainPaneToLibrary {
    if(viewState == VIEW_STATE_LIBRARY)
        return;
    [libraryController refreshDevices:self];
    [libraryController refreshLibraryContents];

    [menuController setSelectionToIndex:0];
    viewState = VIEW_STATE_LIBRARY;

    [self removeSubview]; //clear the area
    [mainPane addSubview:[libraryController view]];
}

在库控制器中:

-(void)refreshLibraryContents {
    [self loadLibraryContents:[rootDir stringByAppendingPathComponent:currentDir]];
}

-(void)loadLibraryContents:(NSString *)folderToLoad {

    int i;
    int currentSelection = [libraryArrayController selectionIndex]; //used to preserve selection and smooth folder changing

    [libraryArrayController setContent:nil];

    //expand the path to load
    folderToLoad = [folderToLoad stringByExpandingTildeInPath];

    NSFileManager * fileManager = [NSFileManager defaultManager]; 
    //load the files in the folder
    NSArray * contents = [fileManager directoryContentsAtPath:folderToLoad];

    //create two seperate arrays for actual files and folders - allows us to add them in order
    NSMutableArray * directories = [[NSMutableArray alloc] init];
    NSMutableArray * musicFiles = [[NSMutableArray alloc] init];

//... a load of stuff filling the file arrays ...

    for(i=0;i<[directories count];i++) {
    [libraryArrayController addObject:[directories objectAtIndex:i]];
    }
    for(i=0;i<[musicFiles count];i++) {
    [libraryArrayController addObject:[musicFiles objectAtIndex:i]];
    }

    if(currentSelection >= 0) {
    [libraryArrayController setSelectionIndex:currentSelection];
    }

    [directories release];
    [musicFiles release];   
}
有帮助吗?

解决方案

问题不在于集合视图尚未完成绘制,而在于它对子视图的添加和删除进行了动画处理。或许有可能 创建交易 当您重新加载集合视图的内容时,它会禁用图层操作。清单 2(暂时禁用层的操作)显示了如何执行此操作。我还没有测试过这个,所以我不知道这是否会达到你想要的效果,但这就是我开始的地方。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top