当我调用[window setFrame:frame animated:YES]来放大窗口时,它可以很好地工作,但它会向上动画并且会在状态栏后面。我该如何使窗口向下动画呢?
只需要将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];
}