- (IBAction)TextField_DidEndOnExit:(id)sender {
// 隱藏鍵盤.
[sender resignFirstResponder];
} - (IBAction)TextField_DidEndOnExit:(id)sender;
- (IBAction)nameTextField_DidEndOnExit:(id)sender {
// 將焦點移至下一個文本框.
[self.passTextField becomeFirstResponder];
}
- (IBAction)passTextField_DidEndOnExit:(id)sender {
// 隱藏鍵盤.
[sender resignFirstResponder];
// 觸發登陸按鈕的點擊事件.
[self.loginButton sendActionsForControlEvents:UIControlEventTouchUpInside];
} - (IBAction)View_TouchDown:(id)sender {
// 發送resignFirstResponder.
[[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil];
} 源碼可以到我的github中下載:https://github.com/colin1994/myKeyboard.git
可以通過自定義鍵盤, 在鍵盤上加入你需要的功能, 即可。
效果如下:

代碼如下:<喎?/kf/ware/vc/" target="_blank" class="keylink">vcD48cD48L3A+PHByZSBjbGFzcz0="brush:java;">- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
if (self.keyboardToolbar == nil)
{
self.keyboardToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 38.0f)];
self.keyboardToolbar.barStyle = UIBarStyleBlackTranslucent;
UIBarButtonItem *previousBarItem = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"前進", @"")
style:UIBarButtonItemStyleBordered
target:self
action:@selector(previousField:)];
UIBarButtonItem *nextBarItem = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"後退", @"")
style:UIBarButtonItemStyleBordered
target:self
action:@selector(nextField:)];
UIBarButtonItem *spaceBarItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
target:nil
action:nil];
UIBarButtonItem *doneBarItem = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"隱藏", @"")
style:UIBarButtonItemStyleDone
target:self
action:@selector(resignKeyboard:)];
[self.keyboardToolbar setItems:[NSArray arrayWithObjects:previousBarItem, nextBarItem, spaceBarItem, doneBarItem, nil]];
}
self.myTextView.inputAccessoryView = self.keyboardToolbar;
}
#pragma mark - your code
- (void)resignKeyboard:(id)sender
{
[self.myTextView resignFirstResponder];
}
- (void)previousField:(id)sender
{
}
- (void)nextField:(id)sender
{
}