0
我正在嘗試在鍵盤顯示上調整UITextView的大小。但是,我的下面的代碼行爲很奇怪。文本視圖跳轉到新的高度,然後再回到原始高度。任何幫助在這裏將不勝感激。調整UITextView的高度動畫
//Handles keyboard appearance
func keyboardWillShow(notification:NSNotification){
var rightButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Done, target: self, action: Selector("dismissKeyboard"))
self.navigationItem.rightBarButtonItem = rightButton
self.origNoteFrame = notes.frame
var duration = NSTimeInterval((notification.userInfo![UIKeyboardAnimationDurationUserInfoKey] as NSNumber).intValue)
var options = UIViewAnimationOptions(
UInt((notification.userInfo![UIKeyboardAnimationCurveUserInfoKey] as NSNumber).integerValue << 16)
)
UIView.animateWithDuration(
duration,
delay: 0.0,
options: options,
animations: {
self.notes.frame = CGRectMake(self.notes.frame.origin.x, self.notes.frame.origin.y, self.notes.frame.width, (notification.userInfo?[UIKeyboardFrameEndUserInfoKey] as NSValue).CGRectValue().origin.y - 10)
},
completion: nil)
}
我遇到你的代碼,我沒有看到這樣的行爲(而另一個問題這裏所說http://stackoverflow.com/questions/26004080/keyboardwillshow-will-only-work-from-the-second這是否會在沒有動畫的情況下發生,只需執行'self.notes.frame = CGRectMake(self.notes.frame.origin.x,self.notes.frame.origin.y,self.notes.frame。寬度,(notification.userInfo?[UIKeyboardFrameEndUserInfoKey]作爲NSValue).CGRectValue()。origin.y - 10)'? – abinop 2014-09-23 20:44:08
@abinop是的,高度仍然回到原來的高度。 – steventnorris 2014-09-23 21:09:45