NSSplitViewの同期

2つのNSSplitViewでSpliterPaneの位置を同期させたい。splitViewDidResizeSubviews:を使えば出来そうだと思いコードを書いてみた。

こんな感じ。

- (void)splitViewDidResizeSubviews:(NSNotification *)notification
{
    NSSplitView* theCurrentSplitView = (NSSplitView *)notification.object;
    NSView*      theParentView       = [theCurrentSplitView superview];
    NSArray*     theParentSubviews   = [theParentView subviews];

    NSArray* theSrcArray;
    theSrcArray = theCurrentSplitView.subviews;

    for(NSView* theDstSplitView in theParentSubviews)
    {
        if( theDstSplitView != theCurrentSplitView && [theDstSplitView isKindOfClass:[NSSplitView class]] )
        {
            NSArray* theDstArray;

            theDstArray = theDstSplitView.subviews;

            if( theSrcArray.count == theDstArray.count )
            {
                NSInteger theCount = theDstArray.count;

                for(NSInteger i = 0; i < theCount; i++)
                {
                    ((NSView*)theDstArray[i]).frame = ((NSView*)theSrcArray[i]).frame;
                }
            }
        }
    }
}

リサイズするとうまく動いてくれない。さて、どうした物か。

プロジェクトファイルは、 SplitViewTest1.zip に置いておきます。