iOS animations-text shaking

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.