#import <UIKit/UIKit.h>
typedef void(^resignFirstResponderBlock)(BOOL hided);
@interface UITextField (hideKeyBoard)
//延时注销第一响应者
-(BOOL)resignFirstResponder:(resignFirstResponderBlock)block;
@end
/**************************************************************************/
#import "UITextField+hideKeyBoard.h"
@implementation UITextField (hideKeyBoard)
/**
* 延时注销第一响应者
*
* @param block 延时后执行的事件
*
* @return 判断
*/
-(BOOL)resignFirstResponder:(resignFirstResponderBlock)block{
dispatch_async(dispatch_get_global_queue(0, 0), ^{
double delayInSeconds = 0.1;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^{
[self resignFirstResponder];
block(YES);
});
});
return YES;
}
@end
/***********************************/
使用:
[textField resignFirstResponder:^(BOOL hided) {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"LoginViewController" bundle:nil];
LoginViewController * loginViewC = [storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
loginViewC.isAutomaticLogin = YES;
[self.navigationController pushViewController:loginViewC animated:YES];
}];
代码下载:代码下载