目前我正在iPhone應用程序中使用UITextField輸入電話號碼,用戶輸入電話號碼,然後如何隱藏鍵盤?因爲這裏沒有返回按鈕,是否有可能加入鍵盤內部完成按鈕,請幫我是否有可能在iPhone中的鍵盤內添加完成按鈕?
由於提前
目前我正在iPhone應用程序中使用UITextField輸入電話號碼,用戶輸入電話號碼,然後如何隱藏鍵盤?因爲這裏沒有返回按鈕,是否有可能加入鍵盤內部完成按鈕,請幫我是否有可能在iPhone中的鍵盤內添加完成按鈕?
由於提前
+1,因爲我給出了相同的答案 –
很好的建議,但從UX的角度來看,它不太方便。 – Andy
閱讀此鏈接,並嘗試在應用程序代碼....
http://iphone-rahulvarma.blogspot.in/2012/03/numericpad-with-done-button.html
你可以用「應用」和「取消」按鈕,並與當時解僱數字鍵盤加inputAccessoryView。
inputAccessoryView
- (void)viewDidLoad
{
[super viewDidLoad];
UIToolbar* numberToolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
numberToolbar.barStyle = UIBarStyleBlackTranslucent;
numberToolbar.items = [NSArray arrayWithObjects:
[[UIBarButtonItem alloc]initWithTitle:@"Cancel" style:UIBarButtonItemStyleBordered target:self action:@selector(cancelNumberPad)],
[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil],
[[UIBarButtonItem alloc]initWithTitle:@"Apply" style:UIBarButtonItemStyleDone target:self action:@selector(doneWithNumberPad)],
nil];
[numberToolbar sizeToFit];
numberTextField.inputAccessoryView = numberToolbar;
}
-(void)cancelNumberPad{
[numberTextField resignFirstResponder];
numberTextField.text = @"";
}
-(void)doneWithNumberPad{
NSString *numberFromTheKeyboard = numberTextField.text;
[numberTextField resignFirstResponder];
}
不使用完成按鈕,你也可以隱藏數字鍵盤通過在視圖
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[yourtextfieldname resignFirstResponder];
}
隨時隨地接觸這種方式聽起來像是你需要推出自己的屏幕鍵盤... – Shark
感謝您的回覆 – SampathKumar
我確切地知道你的意思,我有同樣的問題。但是我並沒有最終創建一個新的OSKB,而是在遠程的一個未使用的密鑰上綁定了「完成」按鈕。 也許你可以得到相同的行爲,如果你嘗試使用後退按鈕,並重寫onBackPressed(); – Shark