[英]iOS: Keep active UITextField in middle of the Screen while Keyboard is shown
[英]iOS UITextField keep keyboard on the screen
我沒有調用“ [sender resignFirstResponder]”方法,但是當按下完成按鈕時,我的鍵盤仍然關閉。 我需要它保持打開狀態,即使單擊完成也是如此。 我該怎么做呢?
這是我控制鍵盤的操作:
- (IBAction)returnKeyButton:(id)sender {
BOOL guessCorrect = [gameModel checkGuess:guessTextField.text];
guessTextField.text = @"";
if (guessCorrect) {
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef soundFileURLRef;
soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"rightAnswer", CFSTR ("mp3"), NULL);
UInt32 soundID;
AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
AudioServicesPlaySystemSound(soundID);
if (gameModel.score == 10) {
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef soundFileURLRef;
soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"win", CFSTR ("mp3"), NULL);
UInt32 soundID;
AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
AudioServicesPlaySystemSound(soundID);
[self endGameWithMessage:@"You win!"];
} else {
scrambledWord.text = [gameModel getScrambledWord];
}
}
remainingTime.text = [NSString stringWithFormat:@"%i", gameModel.time];
playerScore.text = [NSString stringWithFormat:@"%i", gameModel.score];
}
首先,老實說,我從未遇到過您遇到的問題。 我總是不得不使用resign調用來關閉鍵盤,否則它將保持打開狀態……但是,這就是我為您使用的功能:
1)將其放在.h文件中:
-(IBAction) textFieldDoneEditing : (id) sender;
2)將其放在.m文件中:
-(IBAction) textFieldDoneEditing : (id) sender{
[sender resignFirstResponder];
[sender becomeFirstResponder];
}
3)右鍵單擊情節提要中的UITextField,然后在視圖控制器中將已發送事件“ Edited Did End”設置為textFieldDoneEditing方法。
現在,只要用戶按下“返回”或“完成”,鍵盤就會立即打開和關閉。 希望能幫助到你! :)
如果不起作用,請查看我的Xcode項目(起作用)... 在此處下載
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.