iPhone和ipad鍵盤高度及鍵盤響應事件

2021-06-19 07:42:16 字數 1024 閱讀 3896

在ios3.2以後的系統中,蘋果就提供了鍵盤使用的api以及demo程式——「keyboardaccessory」。

處理鍵盤事件的正確方法是這樣的:(包括獲取鍵盤的高度以及鍵盤彈出和消失動畫的時間)

1)在要使用鍵盤的檢視控制器中,接收鍵盤事件的通知:

[[nsnotificationcenter defaultcenter] addobserver:self selector:@selector(keyboardwillshow:) name:uikeyboardwillshownotification object:nil];

[[nsnotificationcenter defaultcenter] addobserver:self selector:@selector(keyboardwillhide:) name:uikeyboardwillhidenotification object:nil];

//鍵盤高度變化通知,ios5.0新增的

#ifdef __iphone_5_0

float version = [[[uidevice currentdevice] systemversion] floatvalue];

if (version >= 5.0)

#endif

2)然後新增鍵盤事件的處理**:

獲取到當前keyboard的高度以及動畫時間,然後對檢視進行對應的操作即可。

#pragma mark -

#pragma mark responding to keyboard events

- (void)keyboardwillshow:(nsnotification *)notification

- (void)keyboardwillhide:(nsnotification *)notification

3)在檢視控制器消除時,移除鍵盤事件的通知:

[[nsnotificationcenter defaultcenter] removeobserver:self];

iPhone和ipad鍵盤高度及鍵盤響應事件 摘

ipad鍵盤高度 portrait 264 landscape 352.iphone鍵盤高度 portrait 216 landscape 140 背景 ios5之前,iphone上的鍵盤的高度是固定為216.0px高的,中文漢字的選擇框是懸浮的,所以不少應用都將此高度來標註鍵盤的高度。可是在ios...

Apple在用Ipad和Iphone玩兒左右互搏

大家一直都在詬病ipad沒有攝像頭,ipad沒有gps,ipad沒有打 的功能 這個功能是我詬病的嘿嘿 沒有方便的外接鍵盤。大家一直還在期盼或者嫉妒或者嚮往或者葡萄酸ipad的功能和外觀和使用者和銷售。ipad的價位足夠承擔ipad的攝像頭 gps 打 外接鍵盤等等成本而盈利,那為什麼ipad不加上...

用CSS簡單區分iPad和iPhone

ipad終於發布了,那麼如果用樣式區分ipad和iphone中的safari瀏覽器,jason grigsby做了乙個有用的實驗。就絕大部分而言,ipad上的移動版safari和iphone上的事一樣的。我發現的乙個不同是,ipad上的webkit支援基於方向 orientation 的css 查詢...