此问题已在此处提出
在目标C中。我试图在Swift中实现接受的答案但是徒劳无功。
我有一个TableView,当键盘出现时我想要偏移表视图,我已按如下方式编写代码 -
在 viewWillAppear()
中self.automaticallyAdjustsScrollViewInsets = false
NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillShow:", name: UIKeyboardWillShowNotification, object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillHide:", name: UIKeyboardWillHideNotification, object: nil)
然后 -
func keyboardWillShow(notification: NSNotification)
{
let contentInsets:UIEdgeInsets!
let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.CGRectValue()
if UIInterfaceOrientationIsPortrait(UIApplication.sharedApplication().statusBarOrientation)
{
contentInsets = UIEdgeInsetsMake(0.0, 0.0, (keyboardSize!.height), 0.0)
}
else
{
contentInsets = UIEdgeInsetsMake(0.0, 0.0, (keyboardSize!.width), 0.0)
}
self.TableVieww.contentInset = contentInsets;
self.TableVieww.scrollIndicatorInsets = contentInsets;
TableVieww.scrollToRowAtIndexPath(self.editingIndexPath, atScrollPosition: UITableViewScrollPosition.Top, animated: true)
}
但是我收到错误 - 类型'SearchVC'的值没有属性'editingIndexPath'。