UIKeyboardDidShowNotification通知已发送两次

时间:2014-04-15 05:03:52

标签: ios iphone nsnotificationcenter

我的视图控制器正在订阅UIKeyboardDidShowNotification中的viewWillAppear并取消订阅viewWillDisappear

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
    [nc addObserver:self
       selector:@selector(keyboardShown)
           name:UIKeyboardDidShowNotification
         object:nil];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
    [nc removeObserver:self name:UIKeyboardDidShowNotification object:nil];
}

- (void)keyboardShown
{
    NSLog(@"Keyboard shown");
}

我也在设置:

self.collectionView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;

当我开始拖动主要收集视图时,它会使键盘消失。

问题是UIKeyboardDidShowNotification已经两次。一旦我按预期聚焦文本字段,一次当我开始拖动滚动视图时,键盘实际上消失

这是一个错误或功能,还是我做错了什么?在没有额外的虚假事件的情况下,我可以选择实际的“键盘显示/隐藏”吗?

0 个答案:

没有答案