码迷,mamicode.com
首页 > 编程语言 > 详细

swift获取键盘高度

时间:2016-03-29 14:45:12      阅读:517      评论:0      收藏:0      [点我收藏+]

标签:

  1. 列表内容

监听键盘起落 下面是可以监听到得四种状态

UIKeyboardWillShowNotification: String 
UIKeyboardDidShowNotification: String 
UIKeyboardWillHideNotification: String 
UIKeyboardDidHideNotification: String

 

NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillAppear:", name: UIKeyboardWillShowNotification, object: nil)

NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillDisappear:", name:UIKeyboardWillHideNotification, object: nil)

  

func keyboardWillAppear(notification: NSNotification) {

        // 获取键盘信息
        let keyboardinfo = notification.userInfo![UIKeyboardFrameBeginUserInfoKey]

        let keyboardheight:CGFloat = (keyboardinfo?.CGRectValue.size.height)!

        print("键盘弹起")

        print(keyboardheight)

    }

    func keyboardWillDisappear(notification:NSNotification){

        print("键盘落下")
    }

  

swift获取键盘高度

标签:

原文地址:http://www.cnblogs.com/torrescx/p/5332673.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!