UIKeyboardWillShowNotification triggered two times on iOS 8 and only one time on iOS 7 when rotating

585 views Asked by At

From the very simple piece of code below, I have a strange behavior difference between iOS 7 and 8 when rotating :

  • On iOS 7 the keyboardWillShow and keyboardWillHide are called only one time each.
  • On iOS 8 the keyboardWillShow and keyboardWillHide are called two times each.

I have created a very simple project to ensure that it was not a side effect of my main project, but it is not.

Is it a documented behavior difference ?

Regards. Sébastien.

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(keyboardWillShow:)
                                                 name:UIKeyboardWillShowNotification
                                               object:self.view.window];


    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(keyboardWillHide:)
                                                 name:UIKeyboardWillHideNotification
                                               object:self.view.window];
}

- (void)viewDidDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)keyboardWillShow:(NSNotification*)notification
{
    NSLog(@"Keyboard will show.");
}

-(void)keyboardWillHide:(NSNotification*)notification
{
    NSLog(@"Keyboard will hide.");
}

@end
1

There are 1 answers

3
Gopal Devra On

Sébastien I think you should add keyboard notification in the viewDidLoad() and then try again, hope it will help you.