如何創建停留在屏幕底部的可移動UItextfield,當鍵盤出現時,它將移動到iphone應用程序中的鍵盤頂部?如何在Xcode 4.2中做到這一點? 就像在WhatsApp和Skype聊天中一樣。 我想用來輸入字符串到表。如何創建可移動的UItextfield?
0
A
回答
1
您應該將viewController註冊爲鍵盤通知的偵聽器。當鍵盤出現時,用戶字典會觸發通知。字典將包含有用的信息,例如相對於屏幕的鍵盤位置,用於將textFields框架動畫到新位置。退房的文件:
具體來說,你想要的通知是:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWasShown:)
name:UIKeyboardDidShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillBeHidden:)
name:UIKeyboardWillHideNotification object:nil];
你要在viewDidLoad中在大多數情況下添加這些。不要忘記在完成後稍後註銷通知(removeObserver :),例如在viewDidUnload中。
0
您可以按照Hubert提到的方法使用通知,或者您可以不斷檢查UITextField是否是第一響應者。如果它是第一響應者,這意味着文本字段被選中並且鍵盤將影響該文本字段。
-(void)viewDidLoad {
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(checkTextField) userInfo:nil repeats:YES];
}
-(void)checkTextField {
if (textField isFirstResponder) {
//the text field has been tapped and the keyboard will come up, so animate the text field moving up here
} else {
//the text field is not selected, so it should be in its original position
}
}
相關問題
- 1. 動態UITextField創建
- 2. Java - 如何創建可移動菜單
- 3. 如何創建多行UITextField?
- 4. 如何創建屏外UITextField
- 5. 創建可移動的幾何對象
- 6. 如何自動移動UIScrollView以使UITextfield基於鍵盤可見?
- 7. 如何創建透明的UITextField?
- 8. UITextfield光標移動
- 9. 動態創建uitextfield的屏幕位置
- 10. 如何以編程方式創建可編輯的UITextField
- 11. 如何移動到創建的片段?
- 12. 創建可移動的文字裝飾
- 13. 如何用不同的對象名創建動態UITextField?
- 14. 誤差的UITextField移動
- 15. 如何在網上創建可移動的菜單或鏈接..?
- 16. 如何創建不可移動的帳戶
- 17. 如何創建可靠的移動服務
- 18. 如何在iOS中創建不可移動的背景?
- 19. 如何創建一個可移動的5型開發環境?
- 20. 如何在Visual Basic中創建可移動的透明窗體?
- 21. 可滾動UITextField
- 22. 我如何創建移動網站?
- 23. 如何創建庫存移動?
- 24. 如何創建移動版本?
- 25. 如何創建水平div移動
- 26. 如何創建非移動CSS樣式
- 27. 如何創建隨機移動號碼
- 28. 如何從頭創建移動網站
- 29. 在Flash中創建可移動窗口
- 30. 創建後可以移動圖形嗎?
檢查此[鏈接](https://github.com/brandonhamilton/inputtoolbar)其開源項目做你想做的。 – 2012-03-24 00:48:59
抱歉,但我認爲這幾乎不適用於XCode 4.2 storyboareding – SultanSh 2012-03-24 16:04:18