forked from BigShow1949/BigShow1949
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
15e0f1b
commit 36db6fb
Showing
10 changed files
with
178 additions
and
8 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+3.87 KB
(100%)
...xcodeproj/project.xcworkspace/xcuserdata/apple.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// | ||
// UITextField+test.h | ||
// test2 | ||
// | ||
// Created by apple on 16/8/24. | ||
// Copyright © 2016年 apple. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
|
||
|
||
@interface UITextField (Shake) | ||
|
||
- (void)shakeWithCompletion:(void (^)())completion; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// | ||
// UITextField+test.m | ||
// test2 | ||
// | ||
// Created by apple on 16/8/24. | ||
// Copyright © 2016年 apple. All rights reserved. | ||
// | ||
|
||
#import "UITextField+Shake.h" | ||
#import <objc/runtime.h> | ||
|
||
@interface UITextField (Shake) | ||
|
||
typedef void (^Completion)(); | ||
@property (nonatomic, copy) Completion completionBlock; | ||
@end | ||
|
||
|
||
|
||
@implementation UITextField (Shake) | ||
|
||
static char const *strAddrKey = "strAddrKey"; | ||
|
||
- (Completion)completionBlock { | ||
return objc_getAssociatedObject(self, strAddrKey); | ||
} | ||
|
||
- (void)setCompletionBlock:(Completion)completionBlock { | ||
objc_setAssociatedObject(self, strAddrKey, completionBlock, OBJC_ASSOCIATION_COPY_NONATOMIC); | ||
} | ||
|
||
|
||
- (void)shakeWithCompletion:(void (^)())completion { | ||
self.completionBlock = completion; | ||
[self _shake:10 direction:1 currentTimes:0 withDelta:5 andSpeed:0.03]; | ||
} | ||
|
||
|
||
/** | ||
* 抖动动画 | ||
* | ||
* @param times 晃动的次数 | ||
* @param direction 标记:形变是往左还是往右 | ||
* @param current 已经晃动的次数 | ||
* @param delta 形变水平距离 | ||
* @param interval 每次晃动的时间 | ||
*/ | ||
- (void)_shake:(int)times direction:(int)direction currentTimes:(int)current withDelta:(CGFloat)delta andSpeed:(NSTimeInterval)interval { | ||
|
||
[UIView animateWithDuration:interval animations:^{ | ||
self.transform = CGAffineTransformMakeTranslation(delta * direction, 0); | ||
} completion:^(BOOL finished) { | ||
if(current >= times) { | ||
self.transform = CGAffineTransformIdentity; | ||
if (self.completionBlock) { | ||
self.completionBlock(); | ||
} | ||
|
||
}else { | ||
|
||
[self _shake:(times - 1) | ||
direction:direction * -1 | ||
currentTimes:current + 1 | ||
withDelta:delta | ||
andSpeed:interval]; | ||
} | ||
}]; | ||
} | ||
|
||
@end | ||
|
13 changes: 13 additions & 0 deletions
13
BigShow1949/Classes/Animations/抖动密码框/YFPasswordShakeViewController.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// YFPasswordShakeViewController.h | ||
// BigShow1949 | ||
// | ||
// Created by apple on 16/8/24. | ||
// Copyright © 2016年 BigShowCompany. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
@interface YFPasswordShakeViewController : UIViewController | ||
|
||
@end |
47 changes: 47 additions & 0 deletions
47
BigShow1949/Classes/Animations/抖动密码框/YFPasswordShakeViewController.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// | ||
// YFPasswordShakeViewController.m | ||
// BigShow1949 | ||
// | ||
// Created by apple on 16/8/24. | ||
// Copyright © 2016年 BigShowCompany. All rights reserved. | ||
// | ||
|
||
#import "YFPasswordShakeViewController.h" | ||
#import "UITextField+Shake.h" | ||
|
||
@interface YFPasswordShakeViewController () | ||
@property (nonatomic, strong) UITextField *textField; | ||
|
||
@end | ||
|
||
@implementation YFPasswordShakeViewController | ||
- (void)viewDidLoad { | ||
[super viewDidLoad]; | ||
|
||
self.view.backgroundColor = [UIColor whiteColor]; | ||
|
||
UITextField *textField = [[UITextField alloc] init]; | ||
textField.text = @"textField"; | ||
textField.frame = CGRectMake(50, 100, 100, 30); | ||
textField.layer.borderColor = [UIColor blackColor].CGColor; | ||
textField.layer.borderWidth = 1.0f; | ||
[self.view addSubview:textField]; | ||
self.textField = textField; | ||
|
||
UIButton *redBtn = [[UIButton alloc] init]; | ||
redBtn.frame = CGRectMake(100, 200, 100, 100); | ||
[redBtn setTitle:@"click here" forState:UIControlStateNormal]; | ||
[redBtn addTarget:self action:@selector(redBtnClick:) forControlEvents:UIControlEventTouchUpInside]; | ||
redBtn.backgroundColor = [UIColor redColor]; | ||
[self.view addSubview:redBtn]; | ||
|
||
} | ||
|
||
- (void)redBtnClick:(UIButton *)redBtn { | ||
[self.textField shakeWithCompletion:^{ | ||
NSLog(@"密码框抖动动画完成"); | ||
}]; | ||
} | ||
|
||
|
||
@end |