FROM : Bill Dudney
DATE : Wed Nov 07 06:54:13 2007
Hello,
Something else to look at is a CAKeyframeAnimation. You would do that
something like this...
- (CAKeyframeAnimation *)vibAnimation:(NSRect)currentFrame {
CAKeyframeAnimation *vibAnimation = [CAKeyframeAnimation
animation];
CGMutablePathRef vibPath = CGPathCreateMutable();
CGPathMoveToPoint(vibPath, NULL, NSMinX(currentFrame),
NSMinY(currentFrame));
// move left 20%
CGPathAddLineToPoint(vibPath, NULL, NSMinX(currentFrame),
NSMinY(currentFrame) - NSMinY(currentFrame) * 0.2);
// move right 20%
CGPathAddLineToPoint(vibPath, NULL, NSMinX(currentFrame),
NSMinY(currentFrame) + NSMinY(currentFrame) * 0.2);
// repeat the bounce as many times as you'd like
// adjust the percentage as much as it takes to make it look as
you wish
CGPathCloseSubpath(vibPath);
vibAnimation.path = vibPath;
// set the duration to whatever looks good
vibAnimation.duration = 1.0f;
// paced makes it smooth throughout the animation
vibAnimation.calculationMode = kCAAnimationPaced;
return vibAnimation;
}
Then set the window's animation dictionary to include your animation...
[myWindow setAnimations:[NSDictionary dictionaryWithObjectsAndKeys:
[self vibAnimation:[myWindow frame]],
@"frameOrigin", nil]];
Then poke the frameOrigin... (there is a less clunky way to do this
I'm sure, I just haven't had time to find it)
[[myWindow animator] setFrame:[myWindow frame]];
Now your window should follow the path defined in the vibAnimation
method (in this case its only going to move once to the left then to
the right then back to where it was).
Not sure if this way or subclassing the NSAnimation class is easier.
But this way uses the snazzy new Core Animation API ;)
HTH,
-bd-
http://bill.dudney.net/roller/objc
On Nov 6, 2007, at 8:01 PM, Nick Zitzmann wrote:
>
> On Nov 6, 2007, at 7:56 PM, Ardian Lazuardi wrote:
>
>> the login window is a sample for this. when user give wrong
>> credential, login window will vibrating.
>>
>> how to do vibrating window in cocoa?
>
>
> Subclass NSAnimation and have it change a window instance variable's
> frame every so often.
>
> Nick Zitzmann
> <http://www.chronosnet.com/>
>
> _______________________________________________
>
> Cocoa-dev mailing list (<email_removed>)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/cocoa-dev/<email_removed>
>
> This email sent to <email_removed>
DATE : Wed Nov 07 06:54:13 2007
Hello,
Something else to look at is a CAKeyframeAnimation. You would do that
something like this...
- (CAKeyframeAnimation *)vibAnimation:(NSRect)currentFrame {
CAKeyframeAnimation *vibAnimation = [CAKeyframeAnimation
animation];
CGMutablePathRef vibPath = CGPathCreateMutable();
CGPathMoveToPoint(vibPath, NULL, NSMinX(currentFrame),
NSMinY(currentFrame));
// move left 20%
CGPathAddLineToPoint(vibPath, NULL, NSMinX(currentFrame),
NSMinY(currentFrame) - NSMinY(currentFrame) * 0.2);
// move right 20%
CGPathAddLineToPoint(vibPath, NULL, NSMinX(currentFrame),
NSMinY(currentFrame) + NSMinY(currentFrame) * 0.2);
// repeat the bounce as many times as you'd like
// adjust the percentage as much as it takes to make it look as
you wish
CGPathCloseSubpath(vibPath);
vibAnimation.path = vibPath;
// set the duration to whatever looks good
vibAnimation.duration = 1.0f;
// paced makes it smooth throughout the animation
vibAnimation.calculationMode = kCAAnimationPaced;
return vibAnimation;
}
Then set the window's animation dictionary to include your animation...
[myWindow setAnimations:[NSDictionary dictionaryWithObjectsAndKeys:
[self vibAnimation:[myWindow frame]],
@"frameOrigin", nil]];
Then poke the frameOrigin... (there is a less clunky way to do this
I'm sure, I just haven't had time to find it)
[[myWindow animator] setFrame:[myWindow frame]];
Now your window should follow the path defined in the vibAnimation
method (in this case its only going to move once to the left then to
the right then back to where it was).
Not sure if this way or subclassing the NSAnimation class is easier.
But this way uses the snazzy new Core Animation API ;)
HTH,
-bd-
http://bill.dudney.net/roller/objc
On Nov 6, 2007, at 8:01 PM, Nick Zitzmann wrote:
>
> On Nov 6, 2007, at 7:56 PM, Ardian Lazuardi wrote:
>
>> the login window is a sample for this. when user give wrong
>> credential, login window will vibrating.
>>
>> how to do vibrating window in cocoa?
>
>
> Subclass NSAnimation and have it change a window instance variable's
> frame every so often.
>
> Nick Zitzmann
> <http://www.chronosnet.com/>
>
> _______________________________________________
>
> Cocoa-dev mailing list (<email_removed>)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/cocoa-dev/<email_removed>
>
> This email sent to <email_removed>
| Related mails | Author | Date |
|---|---|---|
| Ardian Lazuardi | Nov 7, 03:56 | |
| Nick Zitzmann | Nov 7, 04:01 | |
| Bill Dudney | Nov 7, 06:54 |






Cocoa mail archive

