代码之家  ›  专栏  ›  技术社区  ›  Septih

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

  •  0
  • Septih  · 技术社区  · 14 年前

    我正在尝试清理我的应用程序(为10.5构建)上的UI,有一件事相当烦人,那就是当我切换到库时,我重新加载内容,显示项目的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];   
    }
    
    1 回复  |  直到 14 年前
        1
  •  -1
  •   Alex    14 年前

    问题不是集合视图还没有完成绘制,而是它为子视图的添加和删除设置了动画。有可能 create a transaction 这将在重新加载集合视图的内容时禁用层操作。清单2(暂时禁用层的操作)展示了如何做到这一点。我还没有测试过这个,所以我不知道这是否能满足你的要求,但这是我要开始的地方。