使用缓动动画调整大小 [英] Resize NSWindows with easing animation

查看:110
本文介绍了使用缓动动画调整大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用一个好的缓动动画(EaseOut)调整一个NSWindow(主要的)。

I'm trying to resize an NSWindow (the main one) with a nice easing animation (EaseOut).

我可以使用 [NSWindow animator] 但我没有找到一种方法来添加缓动效果。

I can use the [NSWindow animator] but I havn't found a way to add the easing effect.

你有一个想法或代码示例,帮助我这样做?

Do you have an idea or code sample which can help me to do that?

推荐答案

选项1

float Y = 100;
float X = 200;

NSRect frame = [window frame];

frame.origin.y -= Y;
frame.size.height += Y;
frame.size.width += X;

[window setFrame:frame display:YES animate:YES];

选项2

float Y = 100;
float X = 200;

NSRect frame = [window frame];

frame.origin.y -= Y;
frame.size.height += Y;
frame.size.width += X;

NSDictionary *windowResize = @{
    NSViewAnimationTargetKey: window,
    NSViewAnimationEndFrameKey: [NSValue valueWithRect:frame]
};
NSDictionary *oldFadeOut = @{
    NSViewAnimationTargetKey: nil,
    NSViewAnimationEffectKey: NSViewAnimationFadeOutEffect
};
NSDictionary *newFadeIn = @{
    NSViewAnimationTargetKey: nil,
    NSViewAnimationEffectKey: NSViewAnimationFadeInEffect
};

NSArray *animations = @[arrayWithObjects:windowResize, newFadeIn, oldFadeOut];
NSViewAnimation *animation = [[NSViewAnimation alloc] initWithViewAnimations: animations];

[animation setAnimationBlockingMode: NSAnimationBlocking];
[animation setAnimationCurve: NSAnimationEaseIn];
[animation setDuration: 2];     
[animation startAnimation]; 

这篇关于使用缓动动画调整大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆