1
在我建立一個示例,我可以發表評論,我使用tableView添加一個單元格,每次我發佈。它的主要處理,但我遇到一個問題,當我想發表評論時,tableview底部是相同的鍵盤高度,但空,如果將其置於零視圖將下移,然後推頂,這是因爲我當我點擊textview寫文本時移動整個視圖。處理tableView contentIn鍵盤時出現
這是空的空間的的tableView下一個預覽(鍵盤的高度,插圖):Preview of image on Google Drive
另一個圖像,以查看是否我提出的底部(內容插圖)= 0時鍵盤被打開:Preview of second image on Google Drive
func keyboardWillShow(sender:NSNotification){
let userInfo: [NSObject : AnyObject] = sender.userInfo!
keyboardSize = userInfo[UIKeyboardFrameBeginUserInfoKey]!.CGRectValue.size
var contentInsets = UIEdgeInsets()
if wasEmoj == true {
if (UIInterfaceOrientationIsPortrait(UIApplication.sharedApplication().statusBarOrientation)) {
contentInsets = UIEdgeInsetsMake(257.0, 0.0, (self.keyboardSize.height), 0.0);
} else {
contentInsets = UIEdgeInsetsMake(257.0, 0.0, (self.keyboardSize.width), 0.0);
}
self.mytableView.contentInset = contentInsets;
self.mytableView.scrollIndicatorInsets = contentInsets
}else {
if (UIInterfaceOrientationIsPortrait(UIApplication.sharedApplication().statusBarOrientation)) {
contentInsets = UIEdgeInsetsMake(215.0, 0.0,(self.keyboardSize.height), 0.0);
} else {
contentInsets = UIEdgeInsetsMake(215.0, 0.0, (self.keyboardSize.width), 0.0);
}
self.mytableView.contentInset = contentInsets;
self.mytableView.scrollIndicatorInsets = contentInsets
}
}
func textViewDidBeginEditing(textView: UITextView) {
self.animateTextField(commentText, up: true, movementDistance: -215, duration: 0.3)
}
///- animate the view up or down to adapt with keyboard
func animateTextField (textField:UITextView,up:Bool,movementDistance:Int,duration:NSTimeInterval){
let movement : Int = (up ? movementDistance : -movementDistance);
UIView.beginAnimations("animateTextField", context: nil)
UIView.setAnimationBeginsFromCurrentState(true)
if up == true {
UIView.setAnimationDuration(0.38)
}else {
UIView.setAnimationDuration(0.3)
}
self.view.frame = CGRectOffset(self.view.frame, 0, CGFloat(movement))
UIView.commitAnimations()
}