您的位置:首页 > 其它

监听键盘高度oc---swfit

2016-11-29 16:26 183 查看
oc:- (void)viewDidLoad{    [super viewDidLoad];        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];}
- (void)keyboardWillShow:(NSNotification *)noti{    NSDictionary *userInfo = [noti userInfo];    NSValue *v = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];    CGRect keyboardRect = [v CGRectValue];    int height = keyboardRect.size.height;}- (void)keyboardWillHide:(NSNotification *)aNotification{}swift:
    override func viewDidLoad() {        super.viewDidLoad()        NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(keyboardWillShow(_:)), name: UIKeyboardWillShowNotification, object: nil)        NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(keyboardWillHide(_:)), name: UIKeyboardWillHideNotification, object: nil)    }    func keyboardWillShow(noti: NSNotification) {        let userInfo = (noti.userInfo)! as NSDictionary        let v = (userInfo.objectForKey(UIKeyboardFrameEndUserInfoKey)) as! NSValue        let keyboardRect = v.CGRectValue()        let height = keyboardRect.size.height    }    func keyboardWillHide(noti: NSNotification) {    }
                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: