Swift下对于键盘遮挡问题的处理

2015-11-28 10:40:56

[应用开发 | App Dev] ,

Swift语言却是是比ObjC简洁方便得多了。

手机屏幕非常小,开发的时候经常遇到键盘的问题,主要还是记录一下吧。

 

 

首先先绑定键盘弹出的事件

NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardChanged:", name: UIKeyboardDidShowNotification, object: nil)

 

触发键盘的时候,修改背后内容的contentInset

func keyboardChanged(notification: NSNotification) {
    let keyboardSize = (notification.userInfo!["UIKeyboardBoundsUserInfoKey"] as! NSValue).CGRectValue().size
    textEditor.contentInset.bottom = keyboardSize.height
}

 

这个月并没有什么很好玩的干货,就先写着这一篇。

 

 

 

这篇博文发表在 应用开发 | App Dev 目录下,标签为 ,
如需引用,请使用链接:https://note.mc256.dev/?p=785

This article published in 应用开发 | App Dev with tags , .
Cite this page using this link:https://note.mc256.dev/?p=785

您的邮箱地址不会被公开,评论使用Gravatar头像。
Your email address will not be published. This blog is using Gravatar.

正在提交评论... Submitting ...
正在为您准备评论控件 Loading Comment Plugin
Copyright © 2013-2023 mc256. All Rights Reserved.
Powered by WordPress on top of a dual-stack k3s Cluster using JuiceFS.
Wordpress Theme Designed By mc256.
Encrypted By Let's Encrypt.  Hosted On Linode + OVH + AWS.
DNS Provided By Hostker.
Status Page by CloudFlare Worker.