Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KentarouKanno/7d231ce97ac22a92a60c to your computer and use it in GitHub Desktop.
Save KentarouKanno/7d231ce97ac22a92a60c to your computer and use it in GitHub Desktop.
// ViewController
var focusCellIndex: NSIndexPath!
func keyboardDidShow(notification: NSNotification) {
let rect = (notification.userInfo?[UIKeyboardFrameEndUserInfoKey] as! NSValue).CGRectValue()
UIView.animateWithDuration(0, animations: {
self.mainTableView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.viewHeight - rect.height)
}) { (boolValue) -> Void in
let visibleRect = self.mainTableView.bounds
let rectInTableView = self.mainTableView.rectForRowAtIndexPath(self.focusCellIndex)
let result = CGRectContainsRect(visibleRect, rectInTableView);
if !result {
self.mainTableView.scrollToRowAtIndexPath(self.focusCellIndex, atScrollPosition: .Bottom, animated: true)
}
}
}
func setText(index: NSIndexPath,cell: UITableViewCell) {
focusCellIndex = index
}
// Cell
func EditingDidBegin(textfield: CustomTextField) {
parent.setText(textFieldCellItem.index, cell: self)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment