gpt4 book ai didi

ios - KeyboardWillShowNotification 不适用于 iOS > 6.1

转载 作者:可可西里 更新时间:2023-11-01 05:55:52 26 4
gpt4 key购买 nike

初始化部分:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) 
name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification object:nil];

一些方法:

- (void) keyboardWillShow:(NSNotification*) aNotification {
// TO DO
}

释放部分:

[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];

因此在 iOS 6.1 中呈现 View 后不会调用 keyboardWillShow...在 iOS 6.0 中,这段代码可以完美运行。

最佳答案

观察者被添加到哪个“初始部分”?例如,如果您的 View Controller 来自 Storyboard,那么它应该在 - (id)initWithCoder:(NSCoder *)decoder 中。

不过,我的建议是在 viewWillAppear 中设置观察者,并在 viewWillDisappear 中移除它们。这样,设置和拆卸是“平衡的”,并且仅在 View Controller 的内容可见时才处于事件状态。

关于ios - KeyboardWillShowNotification 不适用于 iOS > 6.1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16697282/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com