Jitter of some controls in IOS and IOS

Source: Internet
Author: User

Jitter of some controls in IOS and IOS

 

I saw a post on the Internet over the past two days to discuss the jitter effect when some apps enter the account and password. Then I figured out how to implement it. The code below is shown !!!

First, write a category for the UIView.

 

1 # import <UIKit/UIKit. h> 2 3 typedef NS_ENUM (NSInteger, QHLDirection) {4 rows, 5 QHLDirectionVertical 6}; 7 @ interface UIView (QHLShakes) 8-(void) Direction :( QHLDirection) shakeDirection; 9-(void) shakeWithTimes :( NSInteger) times shakeDirection :( QHLDirection) shakeDirection; 10-(void) shakeWithTimes :( NSInteger) times speed :( CGFloat) speed shakeDirection :( QHLDirection) ShakeDirection; 11-(void) shakeWithTimes :( NSInteger) times speed :( CGFloat) speed range :( CGFloat) range shakeDirection :( QHLDirection) shakeDirection; 12 @ end13 14 15 16 # import "UIView + QHLShakes. h "17 18 @ implementation UIView (QHLShakes) 19-(void) Direction :( QHLDirection) shakeDirection {20 [self shakeWithTimes: 10 speed: 0.05 range: 5 shakeDirection: shakeDirection]; 21} 22 23-(void) shakeWit HTimes :( NSInteger) times shakeDirection :( QHLDirection) shakeDirection {24 [self direction: times speed: 0.05 range: 5 shakeDirection: shakeDirection]; 25} 26 27-(void) shakeWithTimes :( NSInteger) times speed :( CGFloat) speed shakeDirection :( QHLDirection) shakeDirection {28 [self shakeWithTimes: times speed: speed range: 5 shakeDirection: shakeDirection]; 29} 30 31-(void) shakeWithTimes :( NSInteger) times spee D :( CGFloat) speed range :( CGFloat) range shakeDirection :( QHLDirection) shakeDirection {32 [self direction: times speed: speed range: range shakeDirection: shakeDirection currentTimes: 0 direction: 1]; 33} 34/** 35 * @ param times: 36 * @ param speed: 37 * @ param range: 38 * @ param shakeDirection: Direction of the Vibration 39 * @ param currentTimes the current number of vibrations 40 * @ param direction to which side of the vibration 41 */42-(void) viewShakesW IthTiems :( NSInteger) times speed :( CGFloat) speed range :( CGFloat) range shakeDirection :( QHLDirection) shakeDirection currentTimes :( NSInteger) currentTimes direction :( int) direction {43 44 [UIView progress: speed animations: ^ {45 self. transform = (shakeDirection = qhldirehorhorizontal )? CGAffineTransformMakeTranslation (range * direction, 0): CGAffineTransformMakeTranslation (0, range * direction); 46} completion: ^ (BOOL finished) {47 if (currentTimes> = times) {48 [UIView animateWithDuration: speed animations: ^ {49 self. transform = CGAffineTransformIdentity; 50}]; 51 return; 52} 53 # pragma mark-loop to times = currentTimes will jump out of this method 54 [self viewShakesWithTiems: times-155 speed: speed56 range: range57 shakeDirection: shakeDirection58 currentTimes: currentTimes + 159 direction: direction *-1]; 60}]; 61} 62 @ en
In ViewController. m

Import the header file # import "UIView + QHLShakes. h"
1 # import "ViewController. h "2 # import" UIView + QHLShakes. h "3 4 # define QHLFont [UIFont boldSystemFontOfSize: 17] 5 # define QHLColor [UIColor purpleColor] 6 # define QHLCGColor [QHLColor CGColor] 7 8 @ interface ViewController () 9 @ property (nonatomic, strong) UITextField * show; 10 @ property (nonatomic, strong) UISegmentedControl * directBtn; 11 @ end12 13 @ implementation ViewController14 15-(void) view DidLoad {16 [super viewDidLoad]; 17 [self setUpShowTextField]; 18 [self setUpBtn]; 19} 20 21 # pragma mark-show22-(void) setUpShowTextField {23 UITextField * show = [[UITextField alloc] init]; 24 show. frame = CGRectMake (30,360,270, 30); 25 show. textAlignment = NSTextAlignmentCenter; 26 show. text = @ "Are you a pig? "; 27 show. textColor = QHLColor; 28 show. layer. cornerRadius = 5; 29 show. layer. masksToBounds = YES; 30 show. layer. borderWidth = 2.0; 31 show. layer. borderColor = QHLCGColor; 32 self. show = show; 33 [self. view addSubview: show]; 34} 35 # pragma mark-btn36-(void) setUpBtn {37 UIButton * btn = [[UIButton alloc] init]; 38 btn. layer. borderColor = QHLCGColor; 39 btn. frame = CGRectMake (30,430,270, 30); 40 btn. layer. BorderWidth = 2.0; 41 btn. layer. cornerRadius = 5; 42 btn. layer. masksToBounds = YES; 43 [btn setTitle: @ "Click me" forState: UIControlStateNormal]; 44 [btn setTitle: @ "" forState: UIControlStateHighlighted]; 45 [btn setTitleColor: QHLColor forState: UIControlStateNormal]; 46 [self. view addSubview: btn]; 47 48 [btn addTarget: self action: @ selector (btnDidClick) forControlEvents: UIControlEventTouchUpInside]; 49} 50 # p Ragma mark-btn Click Event 51-(void) btnDidClick {52 [self. show shakeWithTimes: 20 speed: 0.05 range: 3 shakeDirection :( self. directBtn. selectedSegmentIndex = 0 )? Qhldirehorizontal: QHLDirectionVertical]; 53} 54 @ end

 

Add a textField and button in-(void) viewDidLoad {}, SET related properties, and add a click event to the button.

 

TextField jitter when a click event is triggered !!!!

 

 

I tried the jitter effects of textField and button myself ~~~

If something is wrong with the novice scum, please give me some advice !!!

 

Related Article

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.