Objective c 如何制作NSWindow setFrame:。。已设置动画:是]功能设置为向下而不是向上?
当我调用我的[window setFrame:frame animated:YES]来放大窗口时,它工作得很好,但它会向上设置动画,并位于状态栏后面。如何使窗口向下设置动画?我找不到一种简单的方法来实现这一点,因此我编写了一个动画函数,可以调整窗口大小,同时移动窗口,从而使其看起来像向下设置动画一样Objective c 如何制作NSWindow setFrame:。。已设置动画:是]功能设置为向下而不是向上?,objective-c,cocoa,nswindow,Objective C,Cocoa,Nswindow,当我调用我的[window setFrame:frame animated:YES]来放大窗口时,它工作得很好,但它会向上设置动画,并位于状态栏后面。如何使窗口向下设置动画?我找不到一种简单的方法来实现这一点,因此我编写了一个动画函数,可以调整窗口大小,同时移动窗口,从而使其看起来像向下设置动画一样 - (IBAction)startAnimations:(id)sender{ NSViewAnimation *theAnim; NSRect firstViewFrame;
- (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];
}
只需将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];
这就是我最终要做的,理想情况下,我想用内置的动画功能做一些事情,但我没有看到一种方法可以做到这一点。这使用内置的动画。