0

NSScrollView と NSTableView に NSTableColumn が含まれています。ボタンを押すと、NSScrollView の幅を Animation で変更します。これが私のコードです:

NSDictionary *myScrollViewDictionary = [[NSDictionary alloc] initWithObjectsAndKeys:
                                               myScrollView,NSViewAnimationTargetKey,
                                               [NSValue valueWithRect:myScrollViewStartFrame],NSViewAnimationStartFrameKey,
                                               [NSValue valueWithRect:myScrollViewEndFrame],NSViewAnimationEndFrameKey, nil];

    NSViewAnimation *animation = [[NSViewAnimation alloc] initWithViewAnimations:@[myScrollViewDictionary]];
    animation.delegate = self;
    animation.duration = 0.2;
    [animation setAnimationBlockingMode:NSAnimationBlocking];
    [animation startAnimation];

これはうまくいきます。

しかし、その間に同じアニメーションで各列の幅を変更したいのですが、問題は NSTableColumn が NSView ではないため、フレームを変更できないことです。アニメーションなしで列の幅のみを変更できます。

誰かがアイデアを持っていますか?

4

1 に答える 1

1

おそらく、すべてを手動で行う独自のカスタム アニメーションを作成する必要があるでしょう。列をアニメーション化するための一般的な考え方は次のとおりです。

- (IBAction)animateColumn:(id)sender
{
  NSTableColumn *tableColumn; // = set your table column
  CGFloat initialWidth = [tableColumn width];
  CGFloat finalWidth; // = whatever

  dispatch_async(dispatch_get_global_queue(0,0), {
    double animationTime = 2; //seconds
    double timeElapsed = 0; //approximate measure; probably good enough

    while (timeElapsed<animationTime)
    {
      double t = timeElapsed/animationTime;

      CGFloat width = t*finalWidth + (1-t)*initialWidth;
      dispatch_async(dispatch_get_main_queue(), ^{
        [tableColumn setWidth:width];
      });

      NSDate *future = [NSDate dateWithTimeIntervalSinceNow:0.02];
      [NSThread sleepUntilDate:future];
      timeElapsed += 0.02;
    }

    dispatch_async(dispatch_get_main_queue(), ^{
      [tableColumn setWidth:finalWidth];
    });
  });
}

これをあなたが望むように適応させることができると思います。おそらく、他のアニメーションを開始するのと同時にこのアニメーションを開始できます (両方に同じ時間を使用し、私の例では 2 を 0.2 に変更します)。

于 2013-06-01T18:54:04.870 に答える