开发者

Animate view size in OS X

Mail.app has a 开发者_如何学编程small activity pane in the lower left corner that slides in when activated. I noticed that it re-dimensions the source list above it during the animation (the scroll bar resizes concurrently).

How can that be achieved? I have not found a built-in way to animate view frames the same way you can do for windows.


You can use Core Animation. An example of frame changing with Core Animation is shown here: http://www.macresearch.org/tutorial-intro-core-animation

You can also use NSViewAnimation to do the animation, as shown here: http://www.cocoadev.com/index.pl?AnimatedNSSplitView

A third way is to do this yourself using GCD:

CGFloat duration = 2; //animation duration (seconds)

int N = 100; //animation fineness
CGFloat dt = duration/N; //time change

dispatch_async(dispatch_get_global_queue(0,0), ^{
  for (int i = 1; i <= N; i++)
  {
    NSDate *future = [NSDate dateWithTimeIntervalSinceNow:dt];
    [NSThread  sleepUntilDate:future];

    //calculate your new frame/splitview setup

    dispatch_async(dispatch_get_main_queue(), ^{
      //apply the new frame/splitview setup
    });
  }
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜