Swift3 0 鍵盤高度監聽獲取

2022-03-03 06:21:29 字數 1266 閱讀 3312

方法:通過通知監聽鍵盤的動態

1.鍵盤的動態有四種:

public

static

let uikeyboardwillshow: nsnotification.name

public

static

let uikeyboarddidshow: nsnotification.name

public

static

let uikeyboardwillhide: nsnotification.name

public

static let uikeyboarddidhide: nsnotification.name

2.下面監聽下彈出之前,和**之前的事件

//

鍵盤彈起

@objc private

func willshow(nottification:nsnotification),

anyhashable("uikeyboardislocaluserinfokey"): 1,

anyhashable("uikeyboardcenterenduserinfokey"): nspoint: ,

anyhashable("uikeyboardboundsuserinfokey"): nsrect: , },

anyhashable("uikeyboardframeenduserinfokey"): nsrect: , },

anyhashable("uikeyboardanimationcurveuserinfokey"): 7,

anyhashable("uikeyboardframebeginuserinfokey"): nsrect: , },

anyhashable("uikeyboardanimationdurationuserinfokey"): 0.25]) */

//取出鍵盤的高度

let keyvalue = info.object(forkey: "

uikeyboardframeenduserinfokey")

let keyrect = (keyvalue as

anyobject).cgrectvalue

let height = keyrect?.size.height

print(height!)

}//鍵盤收起

@objc private

func willhide(nottification:nsnotification)

Swift3 0 建構函式

viewcontroller.swift import uikit 在swift中,同乙個專案中 同乙個命名空間 所有的類預設都是共享的,不需要引用,可以直接訪問,不需要import 所有物件的屬性 var,也可以直接訪問到 class viewcontroller uiviewcontroller...

Swift3 0 異常錯誤

swift3.0 真的很簡單 swift3.0 資料型別 swift3.0 array swift3.0 字典 swift3.0 可選值 swift3.0 集合 swift3.0 流控制 swift3.0 物件和類 swift3.0 屬性 swift3.0 函式和閉包 swift3.0 初始化和釋放...

Swift3 0 空間命名

swift3.0 真的很簡單 swift3.0 資料型別 swift3.0 array swift3.0 字典 swift3.0 可選值 swift3.0 集合 swift3.0 流控制 swift3.0 物件和類 swift3.0 屬性 swift3.0 函式和閉包 swift3.0 初始化和釋放...