Is it possible to bring NSWindows to life with pop music?
I want to use some attractive pop animations in my application NSWindow
. I already know how to animate all the different types of CALayerBacked entities, but I can't figure out if there is a way to animate changes in a frame of mine NSWindow
, for example.
The problem I am facing is that I can animate my NSWindow
contentView (since it is CALayerBacked), but not the position and size of it itself NSWindow
.
I know I could just call it setFrame:display:animate:
, but that doesn't give the same smooth animation as it does in a pop framework.
kPOPViewFrame is not available on OSX. I have to use kPOPLayerBounds instead:
Is there a way to achieve this?
source to share
You can create your own custom properties for any object you like:
+ (id)propertyWithName:(NSString *)aName initializer:(void (^)(POPMutableAnimatableProperty *prop))aBlock
You have set something like this for NSWindow ...
POPAnimatableProperty *windowPositionProperty = [POPAnimatableProperty propertyWithName:@"com.myname.NSWindow.position" initializer:^(POPMutableAnimatableProperty *prop) {
prop.readBlock = ^(NSWindow *window, CGFloat values[]) {
values[0] = window.frame.origin.x;
values[1] = window.frame.origin.y;
};
prop.writeBlock = ^(NSWindow *window, const CGFloat values[]) {
[window setFrameOrigin:CGPointMake(values[0], values[1])];
};
}];
Note the documentation comment that "Custom properties must use reverse DNS name."
And then set up the animation like this:
POPSpringAnimation *endBounce = [POPSpringAnimation animation];
endBounce.property = windowPositionProperty;
endBounce.toValue = [NSValue valueWithCGPoint:targetPosition];
[window pop_addAnimation:endBounce forKey:@"endBounce"];
source to share