UITextFieldなどを使っているとキーボードに対して制御したいときが出てきます。
そのときにキーボードのインスタンスを取得する方法です。
キーボードのインスタンスを取得する
@property (weak, nonatomic) UIView *keyboardView;
//キーボードが表示されるタイミングをハンドリングするためにObserverを追加する
- (void)registerForNotifications
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didReceiveKeyboardDidShowNotification:)
name:UIKeyboardDidShowNotification
object:nil];
}
//キーボードが表示されたときの通知を受け取る
- (void)didReceiveKeyboardDidShowNotification:(NSNotification *)notification
{
self.keyboardView = self.textView.inputAccessoryView.superview;
NSLog(@"%@",self.keyboardView);
//<UIInputSetHostView: 0x7ffb796197f0; frame = (0 344; 320 224); layer = <CALayer: 0x7ffb79619ac0>>
}