For example password error hint, need text to shake about several times, in order to play the role of warning.
In order to invoke ease of use, do a classification. The code is as follows:
. h file
#import <QuartzCore/QuartzCore.h>@interface calayer (Anim)/ * * */-(void) shake; @end
. m file
#import "calayer+anim.h"@implementationCalayer (Anim)/** Shake*/-(void) shake{cakeyframeanimation*KFA = [Cakeyframeanimation animationwithkeypath:@"transform.translation.x"]; CGFloat s=5; Kfa.values= @[@ (-s), @ (0), @ (s), @ (0), @ (-s), @ (0), @ (s), @ (0)]; //Length of TimeKfa.duration =0.3f; //RepeatKfa.repeatcount =2; //removed fromKfa.removedoncompletion =YES; [Self ADDANIMATION:KFA forkey:@"Shake"];}@end
Using the method, it is very simple to import this header file, such as a downgrade:
UILabel * Wrongtip = [[UILabel alloc]initwithframe:cgrectmake (130*screenheightrate+heightbit+heightbit2, SELF.MESSAGEVIEW.WIDTH-40, 15)];
Wrongtip.textcolor = [@ "ff0000" hexcolor];
Wrongtip.text = @ "The broker password is wrong, please re-enter";
Wrongtip.font = [Uifont heitiscwithfontsize:12.f];
Wrongtip.textalignment = Nstextalignmentleft;
[Self.messageview Addsubview:wrongtip];
Shake animation
[Wrongtip.layer shake];
iOS animations-text shaking