
电 话:0
手 机:0
联系人:刘先生
E_mail:2074917417@qq.com
地 址:成都市金牛区
关闭和打开键盘的通知使用方法
从事南昌APP开发的技术人员都知道,在关闭和打开键盘时,iOS系统分别会发出如下广播通知:UIKeyboardDidHideNotification和UIKeyboardDid- ShowNotification。使用广播通知的时候,网络认为大家需要注意的是要在合适的时机注册和解除通知,而ViewController中的有关代码如下:
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
//注册键盘出现通知
NSNotificationCenter.defaultCenter().addObserver(self, selector:
"keyboardDidShow:", name: UIKeyboardDidShowNotification,object: nil)
//注册键盘隐藏通知
NSNotificationCenter.defaultCenter().addObserver(self, selector:
"keyboardDidHide:", name: UIKeyboardDidHideNotification,object: nil)
}
override func viewWillDisappear(animated: Bool) {
super.viewWillDisappear(animated)
//解除键盘出现通知
NSNotificationCenter.defaultCenter().removeObserver(self, name:UIKeyboardDidShowNotification, object: nil)
//解除键盘隐藏通知
NSNotificationCenter.defaultCenter().removeObserver(self, name:UIKeyboardDidHideNotification, object: nil)
}
func keyboardDidShow(notification: NSNotification) {
NSLog("键盘打开")
}
func keyboardDidHide(notification: NSNotification) {
NSLog("键盘关闭")
}
-(void) viewWillAppear:(BOOL)animated {
//注册键盘出现通知
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector (keyboardDidShow:)
name: UIKeyboardDidShowNotification object:nil];
//注册键盘隐藏通知
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector (keyboardDidHide:)
name: UIKeyboardDidHideNotification object:nil];
[super viewWillAppear:animated];
}
-(void) viewWillDisappear:(BOOL)animated {
//解除键盘出现通知
[[NSNotificationCenter defaultCenter] removeObserver:self
name: UIKeyboardDidShowNotification object:nil];
//解除键盘隐藏通知
[[NSNotificationCenter defaultCenter] removeObserver:self
name: UIKeyboardDidHideNotification object:nil];
[super viewWillDisappear:animated];
}
-(void) keyboardDidShow: (NSNotification *)notif {
NSLog(@"键盘打开");
}
-(void) keyboardDidHide: (NSNotification *)notif {
NSLog(@"键盘关闭");
}
南昌APP制作开发公司-网络在此还要跟大家说明的是,注册通知在viewWillAppear:方法中进行,解除通知在viewWillDisappear:方法中进行。keyboardDidShow:消息是在键盘打开时发出的,keyboardDidHide:消息是在键盘关闭时发出的。
看完以上介绍后,大家是否对关于IOS中关闭和打开键盘的通知使用方法有所了解了呢? 如果还有哪些不太明白的地方,可随时来电和我们联系,我们专业为您讲解。此外,本公司专注于APP开发、南昌做网站、微信开发等方面的服务,如有需要,随时为您效劳!
PS:所有作品版权归原创作者所有,与本站立场无关,如不慎侵犯了你的权益,请联系我们告知,我们将做删除处理!
Copyright © 20019-2023 荟萃信息网 版权所有 蜀ICP备16021156号-2
电 话:0 手 机:0 传 真: E-mail:2074917417@qq.com
地 址:成都市金牛区
技术支持:荟萃网络科技
扫码关注我们