Shake visual effect on iPhone (NOT shaking the device)

后端 未结 11 810
忘了有多久
忘了有多久 2020-12-02 05:06

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

11条回答
  •  爱一瞬间的悲伤
    2020-12-02 05:46

    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;
        }
    }
    

提交回复
热议问题