Skip to content

Commit 63568ea

Browse files
committed
autoShowKeyboardDelay
1 parent b97fc5b commit 63568ea

File tree

9 files changed

+157
-1
lines changed

9 files changed

+157
-1
lines changed

.DS_Store

0 Bytes
Binary file not shown.

JHVerificationCodeView.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
088BF8BA1F4FAF3C00B5863B /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 088BF8B81F4FAF3C00B5863B /* LaunchScreen.storyboard */; };
1616
088BF8C51F4FAF3C00B5863B /* JHVerificationCodeViewTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 088BF8C41F4FAF3C00B5863B /* JHVerificationCodeViewTests.m */; };
1717
088BF8D21F4FAF7500B5863B /* JHVerificationCodeView.m in Sources */ = {isa = PBXBuildFile; fileRef = 088BF8D11F4FAF7500B5863B /* JHVerificationCodeView.m */; };
18+
18EE78502507AA8000E7F10D /* NextViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 18EE784F2507AA8000E7F10D /* NextViewController.m */; };
1819
/* End PBXBuildFile section */
1920

2021
/* Begin PBXContainerItemProxy section */
@@ -43,6 +44,8 @@
4344
088BF8C61F4FAF3C00B5863B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
4445
088BF8D01F4FAF7500B5863B /* JHVerificationCodeView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JHVerificationCodeView.h; sourceTree = "<group>"; };
4546
088BF8D11F4FAF7500B5863B /* JHVerificationCodeView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JHVerificationCodeView.m; sourceTree = "<group>"; };
47+
18EE784E2507AA8000E7F10D /* NextViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NextViewController.h; sourceTree = "<group>"; };
48+
18EE784F2507AA8000E7F10D /* NextViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = NextViewController.m; sourceTree = "<group>"; };
4649
/* End PBXFileReference section */
4750

4851
/* Begin PBXFrameworksBuildPhase section */
@@ -89,6 +92,8 @@
8992
088BF8AE1F4FAF3C00B5863B /* AppDelegate.m */,
9093
088BF8B01F4FAF3C00B5863B /* ViewController.h */,
9194
088BF8B11F4FAF3C00B5863B /* ViewController.m */,
95+
18EE784E2507AA8000E7F10D /* NextViewController.h */,
96+
18EE784F2507AA8000E7F10D /* NextViewController.m */,
9297
088BF8B31F4FAF3C00B5863B /* Main.storyboard */,
9398
088BF8B61F4FAF3C00B5863B /* Assets.xcassets */,
9499
088BF8B81F4FAF3C00B5863B /* LaunchScreen.storyboard */,
@@ -228,6 +233,7 @@
228233
isa = PBXSourcesBuildPhase;
229234
buildActionMask = 2147483647;
230235
files = (
236+
18EE78502507AA8000E7F10D /* NextViewController.m in Sources */,
231237
088BF8B21F4FAF3C00B5863B /* ViewController.m in Sources */,
232238
088BF8AF1F4FAF3C00B5863B /* AppDelegate.m in Sources */,
233239
088BF8D21F4FAF7500B5863B /* JHVerificationCodeView.m in Sources */,

JHVerificationCodeView/.DS_Store

0 Bytes
Binary file not shown.

JHVerificationCodeView/JHVerificationCodeView/JHVerificationCodeView.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ typedef NS_ENUM(NSUInteger, JHVCConfigInputType) {
7070
@property (nonatomic, assign) JHVCConfigInputType inputType;
7171
///自动弹出键盘
7272
@property (nonatomic, assign) BOOL autoShowKeyboard;
73+
///默认0.5
74+
@property (nonatomic, assign) CGFloat autoShowKeyboardDelay;
7375
///光标闪烁动画, Default is YES
7476
@property (nonatomic, assign) BOOL showFlickerAnimation;
7577
///显示下划线

JHVerificationCodeView/JHVerificationCodeView/JHVerificationCodeView.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ - (instancetype)init{
4343
_textColor = [UIColor blackColor];
4444
_showFlickerAnimation = YES;
4545
_underLineColor = [UIColor lightGrayColor];
46+
_autoShowKeyboardDelay = 0.5;
4647
}
4748
return self;
4849
}
@@ -197,7 +198,7 @@ - (void)jhSetupViews:(CGRect)frame
197198
//[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(xx_didBecomeActive) name:UIApplicationDidBecomeActiveNotification object:nil];
198199

199200
if (_config.autoShowKeyboard) {
200-
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.25 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
201+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(_config.autoShowKeyboardDelay * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
201202
[_textView becomeFirstResponder];
202203
});
203204
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// NextViewController.h
3+
// JHVerificationCodeView
4+
//
5+
// Created by HaoCold on 2020/9/8.
6+
// Copyright © 2020 HaoCold. All rights reserved.
7+
//
8+
9+
#import <UIKit/UIKit.h>
10+
11+
NS_ASSUME_NONNULL_BEGIN
12+
13+
@interface NextViewController : UIViewController
14+
15+
@end
16+
17+
NS_ASSUME_NONNULL_END
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
//
2+
// NextViewController.m
3+
// JHVerificationCodeView
4+
//
5+
// Created by HaoCold on 2020/9/8.
6+
// Copyright © 2020 HaoCold. All rights reserved.
7+
//
8+
9+
#import "NextViewController.h"
10+
#import "JHVerificationCodeView.h"
11+
12+
#define kScreenWidth [UIScreen mainScreen].bounds.size.width
13+
#define kScreenHeight [UIScreen mainScreen].bounds.size.height
14+
15+
@interface NextViewController ()
16+
17+
@end
18+
19+
@implementation NextViewController
20+
21+
- (void)viewDidLoad {
22+
[super viewDidLoad];
23+
// Do any additional setup after loading the view.
24+
25+
self.title = @"自动弹出键盘";
26+
self.view.backgroundColor = [UIColor whiteColor];
27+
28+
[self jhSetupViews];
29+
}
30+
31+
- (void)jhSetupViews
32+
{
33+
// example 1
34+
{
35+
UILabel *label = [[UILabel alloc] init];
36+
label.frame = CGRectMake(0, 120, kScreenWidth, 30);
37+
label.textAlignment = 1;
38+
label.text = @"InputType: Number & Alphabet";
39+
[self.view addSubview:label];
40+
41+
JHVCConfig *config = [[JHVCConfig alloc] init];
42+
config.inputBoxNumber = 6;
43+
config.inputBoxSpacing = 5;
44+
config.inputBoxWidth = 33;
45+
config.inputBoxHeight = 28;
46+
config.tintColor = [UIColor blackColor];
47+
config.secureTextEntry = NO;
48+
config.inputBoxColor = [UIColor brownColor];
49+
config.font = [UIFont boldSystemFontOfSize:16];
50+
config.textColor = [UIColor blueColor];
51+
config.inputType = JHVCConfigInputType_Number_Alphabet;
52+
53+
54+
config.inputBoxBorderWidth = 1;
55+
config.inputBoxCornerRadius = 5;
56+
57+
// 自动弹出键盘
58+
config.autoShowKeyboard = YES;
59+
config.autoShowKeyboardDelay = 0.7;
60+
61+
config.inputBoxFinishColors = @[[UIColor redColor],[UIColor orangeColor]];
62+
config.finishFonts = @[[UIFont boldSystemFontOfSize:20],[UIFont systemFontOfSize:20]];
63+
config.finishTextColors = @[[UIColor greenColor],[UIColor orangeColor]];
64+
65+
[self.view addSubview:({
66+
67+
UILabel *label = [[UILabel alloc] init];
68+
label.frame = CGRectMake(0, 180, kScreenWidth, 30);
69+
label.textAlignment = 1;
70+
[self.view addSubview:label];
71+
72+
JHVerificationCodeView *codeView =
73+
[[JHVerificationCodeView alloc] initWithFrame:CGRectMake(10, 150, kScreenWidth-20, 30)
74+
config:config];
75+
codeView.finishBlock = ^(JHVerificationCodeView *codeView, NSString *code) {
76+
label.text = code;
77+
78+
// 根据最后输入结果,判断显示哪种颜色
79+
NSUInteger index = [code isEqualToString:@"123asd"] ? 1 : 0;
80+
[codeView showInputFinishColorWithIndex:index];
81+
};
82+
codeView.inputBlock = ^(NSString *code) {
83+
NSLog(@"example 1 code:%@",code);
84+
};
85+
codeView.tag = 100;
86+
codeView;
87+
})];
88+
}
89+
}
90+
91+
92+
/*
93+
#pragma mark - Navigation
94+
95+
// In a storyboard-based application, you will often want to do a little preparation before navigation
96+
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
97+
// Get the new view controller using [segue destinationViewController].
98+
// Pass the selected object to the new view controller.
99+
}
100+
*/
101+
102+
@end

JHVerificationCodeView/ViewController.m

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
#import "ViewController.h"
1010
#import "JHVerificationCodeView.h"
11+
#import "NextViewController.h"
12+
1113

1214
#define kScreenWidth [UIScreen mainScreen].bounds.size.width
1315
#define kScreenHeight [UIScreen mainScreen].bounds.size.height
@@ -35,6 +37,27 @@ - (void)viewDidLoad {
3537
[button addTarget:self action:@selector(clearAction) forControlEvents:1<<6];
3638
button;
3739
})];
40+
41+
self.navigationItem.rightBarButtonItems = @[
42+
[[UIBarButtonItem alloc] initWithCustomView:({
43+
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
44+
button.titleLabel.font = [UIFont systemFontOfSize:16];
45+
[button setTitle:@"清空" forState:0];
46+
[button setTitleColor:[UIColor blackColor] forState:0];
47+
[button sizeToFit];
48+
[button addTarget:self action:@selector(clearAction) forControlEvents:1<<6];
49+
button;
50+
})],
51+
[[UIBarButtonItem alloc] initWithCustomView:({
52+
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
53+
button.titleLabel.font = [UIFont systemFontOfSize:16];
54+
[button setTitle:@"跳转" forState:0];
55+
[button setTitleColor:[UIColor blackColor] forState:0];
56+
[button sizeToFit];
57+
[button addTarget:self action:@selector(jumpAction) forControlEvents:1<<6];
58+
button;
59+
})]
60+
];
3861
}
3962

4063
- (void)jhSetupViews
@@ -266,6 +289,11 @@ - (void)clearAction
266289

267290
}
268291

292+
- (void)jumpAction
293+
{
294+
[self.navigationController pushViewController:[[NextViewController alloc] init] animated:YES];
295+
}
296+
269297
- (void)didReceiveMemoryWarning {
270298
[super didReceiveMemoryWarning];
271299
// Dispose of any resources that can be recreated.

0 commit comments

Comments
 (0)