2012-05-21 134 views
4

我正在使用数字键盘输入来自UITextField。我注意到Interface Builder有一个名为“Done”的返回键属性。当我在返回键选项下选择“完成”时,我没有看到在数字键盘上创建了一个完成按钮。如果将其从数字键盘更改为其他类型,则会在其他键盘类型上看到“完成”按钮,但在使用数字键盘时不会。如何隐藏iOS数字键盘

  • 我想按下
  • 时将隐藏键盘我想这样做,因为房地产的键盘占据了
  • 我量这在键盘上创建一个“完成”按钮非常新的iOS开发,所以最简单和最不复杂的方式来实现这一目标将不胜感激

在此先感谢!

+0

你想实现这个按钮来减少键盘? – 8vius

+0

我只是在我自己的项目上做了这件事,它工作正常,返回按钮变成完成按钮。你有任何额外的代码与键盘混淆? – 8vius

+0

@ 8vius默认情况下,我的数字键盘根本没有返回按钮。右下角的按钮是退格/删除按钮,左下角是空白的。我没有操作键盘的代码。 – Skizz

回答

7

这样做的典型方法是为文本视图的inputAccessoryView属性指定一个包含按钮的工具栏。

+1

+1这是要走的路。 – Till

+0

好的,谢谢你指点我正确的方向。我尝试了一下搜索,似乎有所欠缺。你能指出我的资源涵盖了这个吗?谢谢!! – Skizz

+0

Apple在开发人员库中有一个名为* KeyboardAccessory *的示例项目。 – Jim

0

我发现这个解决方案在线,但它意味着使一个形象,为您完成按钮:http://www.neoos.ch/blog/37-uikeyboardtypenumberpad-and-the-missing-return-key

您也可以使用同样的方法得到UIKeyboard视图显示在本例中,并做到以下几点,按照@吉姆建议:

UIToolbar *keyboardViewToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 206, 320, 44)]; 

UIBarButtonItem *keyboardDoneButton = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(doneSettingDate)]; 
UIBarButtonItem *title = [[UIBarButtonItem alloc] initWithTitle:@"Enter Number" style:UIBarButtonItemStylePlain target:nil action:nil]; 
UIBarButtonItem *spacer1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace 
                     target:nil 
                     action:nil]; 
UIBarButtonItem *spacer2 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace 
                     target:nil 
                     action:nil]; 



NSArray *barButtonItems = [[NSArray alloc] initWithObjects:spacer1, title, spacer2, pickerDoneButton, nil]; 
    [keyboardViewToolbar setItems:barButtonItems]; 

并将该视图添加到键盘视图。

此外,考虑到您刚刚开始,作为一个单独的建议。在iTunes U上,您可以下载适用于iOS的开发应用程序斯坦福大学课程,这是一个非常完整的iOS开发课程,可在iTunes Store上免费获取。

+0

我一定会检查一下。非常感谢! – Skizz

+0

没问题:)开心编码。 – 8vius

0
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) 
    { 
     UIToolbar* KeyBoardToolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)]; 
     KeyBoardToolbar.barStyle = UIBarStyleBlackTranslucent; 
     KeyBoardToolbar.items = [NSArray arrayWithObjects: 
           [[UIBarButtonItem alloc]initWithTitle:[GlobalSettings GetTextBySelectedLocale:@"Done"] style:UIBarButtonItemStyleBordered target:self action:@selector(DismissKeyBoard)], 
           [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil], 
           nil]; 
     [KeyBoardToolbar sizeToFit]; 
     txtMessage.inputAccessoryView = KeyBoardToolbar; 
    } 

txtMessage可能是UiTextFieldUITextView

-(void)DismissKeyBoard{ 
    [self.view endEditing:YES]; 
}