Skip to content

Commit

Permalink
autoShowKeyboardDelay
Browse files Browse the repository at this point in the history
  • Loading branch information
xjh093 committed Sep 8, 2020
1 parent b97fc5b commit 63568ea
Show file tree
Hide file tree
Showing 9 changed files with 157 additions and 1 deletion.
Binary file modified .DS_Store
Binary file not shown.
6 changes: 6 additions & 0 deletions JHVerificationCodeView.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
088BF8BA1F4FAF3C00B5863B /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 088BF8B81F4FAF3C00B5863B /* LaunchScreen.storyboard */; };
088BF8C51F4FAF3C00B5863B /* JHVerificationCodeViewTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 088BF8C41F4FAF3C00B5863B /* JHVerificationCodeViewTests.m */; };
088BF8D21F4FAF7500B5863B /* JHVerificationCodeView.m in Sources */ = {isa = PBXBuildFile; fileRef = 088BF8D11F4FAF7500B5863B /* JHVerificationCodeView.m */; };
18EE78502507AA8000E7F10D /* NextViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 18EE784F2507AA8000E7F10D /* NextViewController.m */; };
/* End PBXBuildFile section */

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

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -89,6 +92,8 @@
088BF8AE1F4FAF3C00B5863B /* AppDelegate.m */,
088BF8B01F4FAF3C00B5863B /* ViewController.h */,
088BF8B11F4FAF3C00B5863B /* ViewController.m */,
18EE784E2507AA8000E7F10D /* NextViewController.h */,
18EE784F2507AA8000E7F10D /* NextViewController.m */,
088BF8B31F4FAF3C00B5863B /* Main.storyboard */,
088BF8B61F4FAF3C00B5863B /* Assets.xcassets */,
088BF8B81F4FAF3C00B5863B /* LaunchScreen.storyboard */,
Expand Down Expand Up @@ -228,6 +233,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
18EE78502507AA8000E7F10D /* NextViewController.m in Sources */,
088BF8B21F4FAF3C00B5863B /* ViewController.m in Sources */,
088BF8AF1F4FAF3C00B5863B /* AppDelegate.m in Sources */,
088BF8D21F4FAF7500B5863B /* JHVerificationCodeView.m in Sources */,
Expand Down
Binary file not shown.
Binary file modified JHVerificationCodeView/.DS_Store
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ typedef NS_ENUM(NSUInteger, JHVCConfigInputType) {
@property (nonatomic, assign) JHVCConfigInputType inputType;
///自动弹出键盘
@property (nonatomic, assign) BOOL autoShowKeyboard;
///默认0.5
@property (nonatomic, assign) CGFloat autoShowKeyboardDelay;
///光标闪烁动画, Default is YES
@property (nonatomic, assign) BOOL showFlickerAnimation;
///显示下划线
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ - (instancetype)init{
_textColor = [UIColor blackColor];
_showFlickerAnimation = YES;
_underLineColor = [UIColor lightGrayColor];
_autoShowKeyboardDelay = 0.5;
}
return self;
}
Expand Down Expand Up @@ -197,7 +198,7 @@ - (void)jhSetupViews:(CGRect)frame
//[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(xx_didBecomeActive) name:UIApplicationDidBecomeActiveNotification object:nil];

if (_config.autoShowKeyboard) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.25 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(_config.autoShowKeyboardDelay * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[_textView becomeFirstResponder];
});
}
Expand Down
17 changes: 17 additions & 0 deletions JHVerificationCodeView/NextViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// NextViewController.h
// JHVerificationCodeView
//
// Created by HaoCold on 2020/9/8.
// Copyright © 2020 HaoCold. All rights reserved.
//

#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

@interface NextViewController : UIViewController

@end

NS_ASSUME_NONNULL_END
102 changes: 102 additions & 0 deletions JHVerificationCodeView/NextViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
//
// NextViewController.m
// JHVerificationCodeView
//
// Created by HaoCold on 2020/9/8.
// Copyright © 2020 HaoCold. All rights reserved.
//

#import "NextViewController.h"
#import "JHVerificationCodeView.h"

#define kScreenWidth [UIScreen mainScreen].bounds.size.width
#define kScreenHeight [UIScreen mainScreen].bounds.size.height

@interface NextViewController ()

@end

@implementation NextViewController

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.

self.title = @"自动弹出键盘";
self.view.backgroundColor = [UIColor whiteColor];

[self jhSetupViews];
}

- (void)jhSetupViews
{
// example 1
{
UILabel *label = [[UILabel alloc] init];
label.frame = CGRectMake(0, 120, kScreenWidth, 30);
label.textAlignment = 1;
label.text = @"InputType: Number & Alphabet";
[self.view addSubview:label];

JHVCConfig *config = [[JHVCConfig alloc] init];
config.inputBoxNumber = 6;
config.inputBoxSpacing = 5;
config.inputBoxWidth = 33;
config.inputBoxHeight = 28;
config.tintColor = [UIColor blackColor];
config.secureTextEntry = NO;
config.inputBoxColor = [UIColor brownColor];
config.font = [UIFont boldSystemFontOfSize:16];
config.textColor = [UIColor blueColor];
config.inputType = JHVCConfigInputType_Number_Alphabet;


config.inputBoxBorderWidth = 1;
config.inputBoxCornerRadius = 5;

// 自动弹出键盘
config.autoShowKeyboard = YES;
config.autoShowKeyboardDelay = 0.7;

config.inputBoxFinishColors = @[[UIColor redColor],[UIColor orangeColor]];
config.finishFonts = @[[UIFont boldSystemFontOfSize:20],[UIFont systemFontOfSize:20]];
config.finishTextColors = @[[UIColor greenColor],[UIColor orangeColor]];

[self.view addSubview:({

UILabel *label = [[UILabel alloc] init];
label.frame = CGRectMake(0, 180, kScreenWidth, 30);
label.textAlignment = 1;
[self.view addSubview:label];

JHVerificationCodeView *codeView =
[[JHVerificationCodeView alloc] initWithFrame:CGRectMake(10, 150, kScreenWidth-20, 30)
config:config];
codeView.finishBlock = ^(JHVerificationCodeView *codeView, NSString *code) {
label.text = code;

// 根据最后输入结果,判断显示哪种颜色
NSUInteger index = [code isEqualToString:@"123asd"] ? 1 : 0;
[codeView showInputFinishColorWithIndex:index];
};
codeView.inputBlock = ^(NSString *code) {
NSLog(@"example 1 code:%@",code);
};
codeView.tag = 100;
codeView;
})];
}
}


/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/

@end
28 changes: 28 additions & 0 deletions JHVerificationCodeView/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#import "ViewController.h"
#import "JHVerificationCodeView.h"
#import "NextViewController.h"


#define kScreenWidth [UIScreen mainScreen].bounds.size.width
#define kScreenHeight [UIScreen mainScreen].bounds.size.height
Expand Down Expand Up @@ -35,6 +37,27 @@ - (void)viewDidLoad {
[button addTarget:self action:@selector(clearAction) forControlEvents:1<<6];
button;
})];

self.navigationItem.rightBarButtonItems = @[
[[UIBarButtonItem alloc] initWithCustomView:({
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.titleLabel.font = [UIFont systemFontOfSize:16];
[button setTitle:@"清空" forState:0];
[button setTitleColor:[UIColor blackColor] forState:0];
[button sizeToFit];
[button addTarget:self action:@selector(clearAction) forControlEvents:1<<6];
button;
})],
[[UIBarButtonItem alloc] initWithCustomView:({
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.titleLabel.font = [UIFont systemFontOfSize:16];
[button setTitle:@"跳转" forState:0];
[button setTitleColor:[UIColor blackColor] forState:0];
[button sizeToFit];
[button addTarget:self action:@selector(jumpAction) forControlEvents:1<<6];
button;
})]
];
}

- (void)jhSetupViews
Expand Down Expand Up @@ -266,6 +289,11 @@ - (void)clearAction

}

- (void)jumpAction
{
[self.navigationController pushViewController:[[NextViewController alloc] init] animated:YES];
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
Expand Down

0 comments on commit 63568ea

Please sign in to comment.