【发布时间】:2011-01-09 23:28:40
【问题描述】:
当我调用我的 [window setFrame: frame animated:YES] 来放大窗口时,它工作得很好,但它会动画化并且它位于状态栏的后面。我怎样才能让窗口动画下来呢?
【问题讨论】:
标签: objective-c cocoa nswindow
当我调用我的 [window setFrame: frame animated:YES] 来放大窗口时,它工作得很好,但它会动画化并且它位于状态栏的后面。我怎样才能让窗口动画下来呢?
【问题讨论】:
标签: objective-c cocoa nswindow
只需减少 y 坐标与增加高度的距离相同。
CGFloat amountToIncreaseWidth = 100, amountToIncreaseHeight = 100;
NSRect oldFrame = [window frame];
oldFrame.size.width += amountToIncreaseWidth;
oldFrame.size.height += amountToIncreaseHeight;
oldFrame.origin.y -= amountToIncreaseHeight;
[window setFrame:oldFrame animated:YES];
【讨论】:
我找不到一个简单的方法来做到这一点,所以我编写了一个动画函数,它可以调整窗口大小并同时移动它,从而使它看起来像动画一样。
- (IBAction)startAnimations:(id)sender{
NSViewAnimation *theAnim;
NSRect firstViewFrame;
NSRect newViewFrame;
NSMutableDictionary* firstViewDict;
{
firstViewDict = [NSMutableDictionary dictionaryWithCapacity:3];
firstViewFrame = [window frame];
[firstViewDict setObject:window forKey:NSViewAnimationTargetKey];
[firstViewDict setObject:[NSValue valueWithRect:firstViewFrame]
forKey:NSViewAnimationStartFrameKey];
newViewFrame = firstViewFrame;
newViewFrame.size.height += 100;
newViewFrame.origin.y -= 100;
[firstViewDict setObject:[NSValue valueWithRect:newViewFrame]
forKey:NSViewAnimationEndFrameKey];
}
theAnim = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray
arrayWithObjects:firstViewDict, nil]];
[theAnim setDuration:1.0];
[theAnim startAnimation];
[theAnim release];
}
【讨论】: