views:

612

answers:

4

On login failure, I'd prefer to avoid showing an alert, it's too fleeting. Showing the alert and then showing the text somewhere on the login screen seems like duplication.

So I'd like for it to graphically shake my login view when the user enters the wrong user ID and password like the Mac login screen does.

Anyone know if there's a way to pull this off, or have any suggestions for another effect I could use?

+1  A: 

I like the shake effect idea. Don't know how to implement it though. Probably some sort of animation.

Are you also going to vibrate or do you think that will be way too annoying?

Epsilon Prime
Oh, that's a good idea too. Will add that, thanks.
Steven Fisher
(Not sure why someone flagged you down, since you did provide an answer to the question. Flagged up. Please, guys, read the whole question before you flag it down.)
Steven Fisher
I like the idea of doing a vibration at the same time: AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
slf
Yeah, I've the vibrate already. Even without the window shake (doing that next) it helps.
Steven Fisher
+4  A: 

Simply changing the X coordinate of the center property of your view might do the trick. If you haven't done any core animation before it's pretty straight-forward.

First, start an animation right, then listen for it to finish, and then move back to the left, and so on. Getting the timing down so it "feels right" might take a while.

- (void)animationFinishCallback:(NSString *)animationID finished:(BOOL)finished context:(void *)context
{
  if ([animationID isEqualToString:@"MoveRight"]) {
    [UIView beginAnimations:@"MoveLeft" context:NULL];
    [UIView setAnimationDuration:1.0];
    [UIView setAnimationDelay: UIViewAnimationCurveEaseIn];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(animationFinishCallback:finished:context:)];

    myView.center = CGRectMake(newX, newY);
    [UIView commitAnimations];
  }
}
slf
You could also create an animation and apply it to the view's `CALayer`. This would let you use, for example, a `CAKeyframeAnimation` which would let you fine-tune the animation. For an animation like this, you'll probably need that level of flexibility.
Alex
+5  A: 

Here's a tutorial that details how to do it in Cocoa. Should be the same for the iPhone (or at least quite similar).

http://www.cimgf.com/2008/02/27/core-animation-tutorial-window-shake-effect/

Justin Gallagher
+6  A: 

I had seen some wobble animation and changed it to shake a view t pixels upright and downleft:

- (void)earthquake:(UIView*)itemView
{
    CGFloat t = 2.0;

    CGAffineTransform leftQuake  = CGAffineTransformTranslate(CGAffineTransformIdentity, t, -t);
    CGAffineTransform rightQuake = CGAffineTransformTranslate(CGAffineTransformIdentity, -t, t);

    itemView.transform = leftQuake;  // starting point

    [UIView beginAnimations:@"earthquake" context:itemView];
    [UIView setAnimationRepeatAutoreverses:YES]; // important
    [UIView setAnimationRepeatCount:5];
    [UIView setAnimationDuration:0.07];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(earthquakeEnded:finished:context:)];

    itemView.transform = rightQuake; // end here & auto-reverse

    [UIView commitAnimations];
}

- (void)earthquakeEnded:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context 
{
    if ([finished boolValue]) 
    {
     UIView* item = (UIView *)context;
     item.transform = CGAffineTransformIdentity;
    }
}
jayccrown
what I needed :D
Allisone