iOS密码框实现(二)取消确定按钮
typedefvoid(^selfhandleInputPasswordBlock)(NSString *password ,IDSGameRoomSecretView *secretView);
@interface IDSGameRoomSecretView : UIView
- (instancetype)initWithselfPasswordCallBack:(selfhandleInputPasswordBlock)passwordCallback;
/**
* 弹出密码框视图
*/
- (void)showInputSecretView;
/**
* 移除密码框view 通过外部通过block来移除
*/
- (void)removeView;
/**
* 重置密码操作
*/
-(void)resetTextField;
@end
{
if (self = [superinit]) {
self.onselfHandlePasswordCallBack = passwordCallback;
}
returnself;
}
{
self.backgroundColor = [UIColorcolorWithRed:0green:0blue:0alpha:0.7];
[[AppDelegatemainWindow] addSubview:self];
[self.inputViewbecomeFirstResponder];
self.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
UITapGestureRecognizer *selfRecognizer = [[UITapGestureRecognizeralloc] initWithTarget:selfaction:@selector(removeView)];
self.userInteractionEnabled = YES;
[selfaddGestureRecognizer:selfRecognizer];
selfRecognizer.delegate = self;
self.secretRoomView = [[UIViewalloc] initWithFrame:CGRectMake(0, 0, 510/2, 290/2)];
self.secretRoomView.backgroundColor = [UIColorwhiteColor];
self.secretRoomView.centerX = SCREEN_WIDTH/2;
self.secretRoomView.centerY = SCREEN_HEIGHT/2-50;
_titleLabel = [[UILabelalloc] initWithFrame:CGRectMake(0, 50/2, 0, 0)];
_titleLabel.text = @"房间已加锁";
_titleLabel.textColor = NF_Color_C3;
_titleLabel.font = [UIFontsystemFontOfSize:Near_Final_Font_T6];
[_titleLabelsizeToFit];
_titleLabel.centerX = self.secretRoomView.frame.size.width/2;
[self.secretRoomViewaddSubview:_titleLabel];
_subtitleLabel = [[UILabelalloc] initWithFrame:CGRectMake(0,CGRectGetMaxY(self.titleLabel.frame)+10, 0, 0)];
_subtitleLabel.text = @"输入房间密码";
_subtitleLabel.textColor = NF_Color_C10;
_subtitleLabel.font = [UIFontsystemFontOfSize:Near_Final_Font_T9];
[_subtitleLabelsizeToFit];
_subtitleLabel.centerX = self.secretRoomView.frame.size.width/2;
[self.secretRoomViewaddSubview:_subtitleLabel];
self.textFieldArray = [NSMutableArrayarray];
NSArray *views = [selfsubviews];
for (UITextField *tf in views) {
[tf removeFromSuperview];
}
for (int i=0;i<4;++i) {
PZXVerificationTextField *tf = [[PZXVerificationTextFieldalloc] initWithFrame:CGRectMake(70/2+i*70/2+15*i, CGRectGetMaxY(self.subtitleLabel.frame)+15, 70/2, 70/2)];
[tf setFont:[UIFontsystemFontOfSize:Near_Final_Font_T5]];
[tf setTextColor:NF_Color_C4];
tf.backgroundColor = [UIColorclearColor];
tf.layer.borderWidth = 0.5;
tf.layer.borderColor = NF_Color_C9.CGColor;
tf.layer.cornerRadius = 5.f;
tf.layer.masksToBounds = YES;
tf.tintColor =[UIColorclearColor];
tf.tag = 100+i;
tf.keyboardType = UIKeyboardTypeNumberPad;
tf.textAlignment = NSTextAlignmentCenter;
tf.delegate = self;
tf.pzx_delegate = self;
[self.secretRoomViewaddSubview:tf];
[self.textFieldArraycl_addObject:tf];
[tf becomeFirstResponder];
}
[selfaddSubview:self.secretRoomView];
self.secretRoomView.layer.cornerRadius = 10.f;
self.secretRoomView.layer.masksToBounds = YES;
}
- (void)removeView
{
[selfremoveFromSuperview];
}
-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
textField.text = string;
if (textField.text.length > 0) {
if (textField.tag< [[_textFieldArraylastObject] tag]) {
UITextField *newTF = (UITextField *)[selfviewWithTag:textField.tag+1];
[newTF becomeFirstResponder];
}
}
for (UITextField *tf inself.textFieldArray) {
if([tf.textisEqualToString:@""]) {
returnNO;
}
}
if (![_queryNoticeTimerisValid]) {
[selfstartQueryTimer];
}
returnNO;
}
#pragma mark - PZXTextFieldDelegate
-(void)PZXTextFieldDeleteBackward:(PZXVerificationTextField *)textField{
if (textField.tag > [[_textFieldArrayfirstObject] tag]) {
UITextField *newTF = (UITextField *)[selfviewWithTag:textField.tag-1];
newTF.text = @"";
[newTF becomeFirstResponder];
}
}
for (UITextField *tf inself.textFieldArray) {
tf.text = @"";
[tf resignFirstResponder];
}
[[_textFieldArrayfirstObject] becomeFirstResponder];
}
NSString *str = [NSStringstring];
for (int i = 0; i<_textFieldArray.count; i++) {
str = [str stringByAppendingString:[NSStringstringWithFormat:@"%@",(UITextField *)[_textFieldArray[i] text]]];
}
if (self.onHandlePasswordCallBack) {
self.onHandlePasswordCallBack(str);
}
if (self.onselfHandlePasswordCallBack) {
self.onselfHandlePasswordCallBack(str,self);
}
[selfstopQueryTimer];
}
for (UITextField *tf inself.textFieldArray) {
[tf resignFirstResponder];
}
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
if ([touch.viewisDescendantOfView:self.secretRoomView]) {
returnNO;
}
returnYES;
}
{
[selfstopQueryTimer];
if (nil == _queryNoticeTimer) {
_queryNoticeTimer = [NSTimerscheduledTimerWithTimeInterval:sIntervalTime
target:self
selector:@selector(getVertificationCode)
userInfo:nilrepeats:NO];
}
}
- (void)stopQueryTimer
{
if (self.queryNoticeTimer) {
[self.queryNoticeTimerinvalidate];
_queryNoticeTimer = nil;
}
}
最新文章
- MyBatis:统计数量
- Redis中Value使用hash类型的效率是普通String的两倍
- C++中const 的各种用法
- Qt 程序运行图标
- poj 2239 Selecting Courses (二分匹配)
- layout_weight的使用说明
- 在子线程中使用runloop,正确操作NSTimer计时的注意点 三种可选方法
- SPOJ 2916 Can you answer these queries V(线段树-分类讨论)
- 统计计算与R语言的资料汇总(截止2016年12月)
- 【转载】Java的四种引用
- 关于iOS元旦http,https的规定,官方论坛回应
- c# 创建,加载,修改XML文档
- 实验六 MapReduce实验:二次排序
- 什么是Unicode
- SQL-7查找薪水涨幅超过15次的员工号emp_no以及其对应的涨幅次数t (group 与count)
- 【C++程序员学 python】python split and join 分割与合并
- Unicode编码:保存中文cookie
- linux的性能优化
- LeetCode: Rotate List 解题报告
- HTML(form标签)、CSS
热门文章
- Delphi 的内存操作函数(1): 给字符指针分配内存( 给字符指针(PChar、PWideChar、PAnsiChar)分配内存最佳的选择是StrAlloc。分配内存的时候会对字符串进行初始化)
- 11991 - Easy Problem from Rujia Liu?(的基础数据结构)
- python下载图片(3)
- 如何导入以前的qq聊天记录
- 狄利克雷过程(Dirichlet Process)
- Android面HTTP协议发送get要求
- WPF字体图标——IconFont
- if-then和if-then-else声明
- Matlab Tricks(二十三)—— 保存图像到 pdf
- [ 转]Node.js模块 require和 exports