当我调用我的[window setFrame:frame animated:YES]来放大窗口时,它工作得很好但是它会动画并且它会在状态栏后面。如何让窗口生成动画呢?
答案 0 :(得分:13)
将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];
答案 1 :(得分:3)
我找不到一个简单的方法来做这个,所以我写了一个动画函数,它会调整窗口大小并同时移动它,从而给出它动画效果的外观。
- (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];
}