How can I make the NSWindow setFrame: .. animated: YES] function animated rather than up?

When I call my [window setFrame: frame animated: YES] to enlarge the window, it works fine, but it animates and goes beyond the status bar. How can I make the window animated down?

+4
source share
2 answers

Just reduce the y coordinate at the same distance as the height.

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]; 
+12
source

I could not find an easy way to do this, so I wrote an animation function that would resize the window and move it at the same time, thereby giving the appearance of the animation.

 - (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]; } 
+4
source

Source: https://habr.com/ru/post/1334815/


All Articles