<!-- lang: cpp -->
NSNotificationCenter.defaultCenter().addObserver(self,
selector: "keyboardWillShowNotification:",
name: UIKeyboardWillShowNotification,
object: nil)
NSNotificationCenter.defaultCenter().addObserver(self,
selector: "keyboardWillHideNotification:",
name: UIKeyboardWillHideNotification,
object: nil)
func keyboardWillShowNotification(notification: NSNotification){
var info:NSDictionary = notification.userInfo!
var keyheight = (info[UIKeyboardFrameEndUserInfoKey] as! NSValue).CGRectValue().height
var height = keyheight + subview.frame.height
if(height > self.view.frame.height){
let n = KeyboardNotification(notification)
let animationDuration = n.animationDuration
let animationCurve = n.animationCurve
self.view.layoutIfNeeded()
UIView.animateWithDuration(animationDuration,
delay: 0,
options: UIViewAnimationOptions(rawValue: UInt(animationCurve << 16)),
animations: {
self.top.constant = self.view.frame.height - height
self.view.layoutIfNeeded()
},
completion: nil
)
}
}
func keyboardWillHideNotification(notification: NSNotification){
let n = KeyboardNotification(notification)
let animationDuration = n.animationDuration
let animationCurve = n.animationCurve
self.view.layoutIfNeeded()
UIView.animateWithDuration(animationDuration,
delay: 0,
options: UIViewAnimationOptions(rawValue: UInt(animationCurve << 16)),
animations: {
self.top.constant = 0
self.view.layoutIfNeeded()
},
completion: nil
)
}
swift 输入字数统计 中文、英文、符号均为一个字符
<!-- lang: cpp -->
var temp = "";
for c:Character in alltext {
if((++length) <= 200){
temp.append(c)
}
}