欧美亚洲大片-国产免费成人在线视频-国产成人8x人在线视频软件-日韩亚洲欧美中文字幕-97伦伦午夜电影理伦片-亚洲综合精品视频-曰本女人牲交高潮视频-久久久精品欧美-天天干天天操天天碰-精品国产乱码久久久久久1区2区-黄色一级免费片-在线免费欧美-国产成人精品在线视频-精人妻一区二区三区-香蕉视频2020-综合久久99-欧美日韩亚洲国产综合

十年專注于品牌網(wǎng)站建設(shè) 十余年專注于網(wǎng)站建設(shè)_小程序開發(fā)_APP開發(fā),低調(diào)、敢創(chuàng)新、有情懷!
南昌百恒網(wǎng)絡(luò)微信公眾號 掃一掃關(guān)注
小程序
tel-icon全國服務(wù)熱線:400-680-9298,0791-88117053
掃一掃關(guān)注百恒網(wǎng)絡(luò)微信公眾號
掃一掃打開百恒網(wǎng)絡(luò)微信小程序

百恒網(wǎng)絡(luò)

南昌百恒網(wǎng)絡(luò)

關(guān)閉和打開鍵盤的通知使用方法

百恒網(wǎng)絡(luò) 2017-09-30 7153

從事南昌APP開發(fā)的技術(shù)人員都知道,在關(guān)閉和打開鍵盤時,iOS系統(tǒng)分別會發(fā)出如下廣播通知:UIKeyboardDidHideNotification和UIKeyboardDid- ShowNotification。使用廣播通知的時候,百恒網(wǎng)絡(luò)認(rèn)為大家需要注意的是要在合適的時機注冊和解除通知,而ViewController中的有關(guān)代碼如下:

override func viewWillAppear(animated: Bool) {

super.viewWillAppear(animated)

//注冊鍵盤出現(xiàn)通知

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)

//解除鍵盤出現(xiàn)通知

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("鍵盤關(guān)閉")

}

-(void) viewWillAppear:(BOOL)animated {

//注冊鍵盤出現(xiàn)通知

[[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 {

//解除鍵盤出現(xiàn)通知

[[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(@"鍵盤關(guān)閉");

}

南昌APP制作開發(fā)公司-百恒網(wǎng)絡(luò)在此還要跟大家說明的是,注冊通知在viewWillAppear:方法中進行,解除通知在viewWillDisappear:方法中進行。keyboardDidShow:消息是在鍵盤打開時發(fā)出的,keyboardDidHide:消息是在鍵盤關(guān)閉時發(fā)出的。

看完以上介紹后,大家是否對關(guān)于IOS中關(guān)閉和打開鍵盤的通知使用方法有所了解了呢? 如果還有哪些不太明白的地方,可隨時來電和我們聯(lián)系,我們專業(yè)為您講解。此外,本公司專注于APP開發(fā)、南昌做網(wǎng)站、微信開發(fā)等方面的服務(wù),如有需要,百恒隨時為您效勞!


400-680-9298,0791-88117053
掃一掃關(guān)注百恒網(wǎng)絡(luò)微信公眾號
掃一掃打開百恒網(wǎng)絡(luò)小程序

歡迎您的光顧,我們將竭誠為您服務(wù)×

售前咨詢 售前咨詢
 
售前咨詢 售前咨詢
 
售前咨詢 售前咨詢
 
售前咨詢 售前咨詢
 
售前咨詢 售前咨詢
 
售后服務(wù) 售后服務(wù)
 
售后服務(wù) 售后服務(wù)
 
備案專線 備案專線
 
×
政和县| 河北省| 咸丰县| 安义县| 隆化县| 承德市| 松滋市| 庆城县| 孝义市| 衡南县| 隆子县| 浑源县| 夏津县| 稷山县| 揭东县| 永福县| 清流县| 迭部县| 诏安县| 巴林右旗| 福泉市| 吉安市| 芒康县| 长葛市| 滁州市| 固镇县| 宁乡县| 固始县| 东平县| 休宁县| 常熟市| 广灵县| 鄂温| 泸州市| 通许县| 黄浦区| 嘉黎县| 恩施市| 阿城市| 彩票| 广元市|