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

发布于 2024-09-06 04:03:02 字数 2026 浏览 2 评论 0原文

我正在尝试清理我的应用程序上的 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];   
}

I'm trying to clean up the UI on my application (built for 10.5) and one thing that's rather annoying is that when I swap to the library I reload the contents and the nscollectionview that displays the items fades the old content out before fading the new ones in. I don't mind the fade in/out of old/new items, but the way i've programmed the view swapping should make the library reload happen before the the nsview that contains the nscollectionview is inserted into the main window.

Anyone had this sort of problem before?

Here's an abridged version of how the swap between different parts of the application to the library goes:

In the main controller:

-(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]];
}

In the library controller:

-(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];   
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

多孤肩上扛 2024-09-13 04:03:02

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

The issue is not that the collection view hasn't finished drawing, it's that it animates the adding and removal of the subviews. It may be possible to create a transaction that disables layer actions while you're reloading the collection view's content. Listing 2 (temporarily disabling a layer's actions) shows how to do this. I haven't tested this, so I don't know if this will do what you want, but this is where I'd start.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文