UIKeyboardWillShowNotification在iOS 8上触发两次,在iOS 7上只旋转一次

时间:2015-06-21 15:02:59

标签: ios ios7 ios8 keyboard nsnotification

从下面的一段非常简单的代码中,我在旋转时在iOS 7和8之间存在奇怪的行为差异:

  • 在iOS 7上,keyboardWillShow和keyboardWillHide每次只调用一次。
  • 在iOS 8上,每次调用keyboardWillShow和keyboardWillHide两次。

我创建了一个非常简单的项目,以确保它不是我的主项目的副作用,但事实并非如此。

是否存在记录在案的行为差异?

的问候。 塞巴斯蒂安。

@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 个答案:

答案 0 :(得分:0)

塞巴斯蒂安 我认为您应该在viewDidLoad()中添加键盘通知,然后再试一次,希望它能为您提供帮助。