キーボードに固定されたカスタムUIViewを作成したいが、入力アクセサリビューを使用したが、キーボードが離れているときにはView Controllerに残りません。 iOS Objective-Cの(入力アクセサリビューのような)キーボードに固定するビューコントローラの一番下に制限されたUIViewを持つにはどうすればよいですか?iOS objective-cのキーボードに固執するカスタムUIView
答えて
ビューのbottomConstraintためIBOutletを追加します。私はそれがViewControllerのビューの直接的なサブビューであると仮定し、キーボードが隠されているときにはその底部にあるはずです。
@IBOutlet weak var bottomConstraint: NSLayoutConstraint!
viewWillAppearでキーボード通知登録:viewDidDisappearで
NotificationCenter.default.addObserver(self, selector: #selector(ViewController.showKeyboard), name: NSNotification.Name.UIKeyboardWillShow, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(ViewController.hideKeyboard), name: NSNotification.Name.UIKeyboardWillHide, object: nil)
購読解除:
後でのViewControllerでNotificationCenter.removeObserver(self)
:
func showKeyboard(_ notification: NSNotification) {
let info = notification.userInfo
let rectValue = info![UIKeyboardFrameEndUserInfoKey] as? NSValue
if let keyboardSize = rectValue?.cgRectValue.size {
bottomConstraint.constant = (keyboardSize?.height)!
view.layoutIfNeeded()
}
}
func hideKeyboard(_ notification: Notification) {
bottomConstraint.constant = 0
view.layoutIfNeeded()
}
Objective-C:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
}
- (void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
}
-(void)keyboardWillShow: (NSNotification *) notification {
CGSize keyboardSize = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
_bottomConstraint.constant = keyboardSize.height;
[view layoutIfNeeded];
}
-(void)keyboardWillHide: (NSNotification *) notification {
_bottomConstraint.constant = 0;
[view layoutIfNeeded];
}
あなたのテキストフィールドにinputAccessoryViewを追加する必要があります。
例
self.mytextField.inputAccessoryView = view;
・ホープこれはあなたの問題を解決
これは問題を解決しません。キーボードが表示されていないときは、入力アクセサリビューが消えます。私はキーボードが表示されていなくても、私が最初に置いた場所に私の治療法を表示したい。 –
ああ、このケースでは、あなたの下にビューを追加する必要があります参照してください。キーボードのキーボード/キーボードで通知を非表示にすると、そのビューの位置を変更する必要があります。 –
このヘルプはhttp://kingscocoa.com/tutorials/keyboard-content-offset/ –
- 1. UIView内の固定キーボード
- 2. ダイナミックプログラミングに固執
- 3. Pythonオープンファイルメソッドに固執する
- 4. iOS:キーボードのUIToolbarまたはUIView
- 5. iOS - viewForFooterInSectionはUITableViewの下部に固執します
- 6. カーソルの作成に固執
- 7. 「ユニークキー」の警告に固執
- 8. iOS ObjectiveC Webservice
- 9. iOSでキーボード上にUIViewを表示するには
- 10. 私のカスタムUIViewのキーボードを表示させる
- 11. カスタム絵文字iOSキーボードの作成
- 12. iOS固定フッタUIViewをマルチスクリーンアプリに追加する
- 13. iOS:ペン先からカスタムUIViewをロード
- 14. Gerritのインストールに固執しました
- 15. UITextViewカスタム入力(キーボードなし)iOS
- 16. EXC_BAD_ACCESS(カスタムXIBでのカスタムUIView)
- 17. 左右サイドバー+ tabbarController(IOS Objectivec)
- 18. UIViewのフレームを取得する方法 - ObjectiveC
- 19. PowerApps - UpdateContextに固執しよう
- 20. PHP正方形APIに固執 - AUTHENTICATION_ERROR
- 21. アプリケーションがダウンロードに固執しました
- 22. UISwipeGestureカスタムUIViewの
- 23. iOSでカスタムUIViewのサイズを変更する方法
- 24. iosのキーボードが固定位置のヘッダーを移動します。
- 25. の取得データは、リターンなステートメントのために固執する
- 26. キーボード入力を受け取るカスタムiOSコントロールを作成する
- 27. カスタムUIViewのイベント
- 28. IBのカスタムUIView
- 29. 休止状態でメインの方法に固執する
- 30. モバイルSafari iOS 6.0固定位置でのキーボードの表示
Objective-Cが優先されました。あなたの答えを編集することができればお願いします。 –
@OmotayoOluwatobiよろしくおねがいします;) – alexburtnik
何らかの理由でautolayoutを使用しない場合は、bottomConstraint.constantを変更する代わりにフレームを手動で更新する必要があります。 – alexburtnik