LoginSignup
2
2

More than 5 years have passed since last update.

UITextField(UITextView)を使用したときのキーボードのViewを取得する

Last updated at Posted at 2014-11-20

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>>
}
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2