vibrating window

  • hi all,

    i want to implement vibrating window when user put wrong information to
    my application.

    the login window is a sample for this. when user give wrong credential,
    login window will vibrating.

    how to do vibrating window in cocoa?

    thank you for any help.

    --
    ardian
  • 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/>
  • 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/
previous month november 2007 next month
MTWTFSS
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30    
Go to today