Container View Wont Raise - ios

I have some code that is supposed to raise a container view when the keyboard comes in to enter some text. I feel like I have definitely
implemented this right but the text view is not raising.
var bottomConstraint: NSLayoutConstraint?
override func viewDidLoad() {
super.viewDidLoad()
navigationItem.title = "Comments"
collectionView?.backgroundColor = UIColor.white
self.navigationItem.hidesBackButton = true
let backButton = UIBarButtonItem(image: UIImage(named: "icons8-Back-64"), style: .plain, target: self, action: #selector(GoBack))
self.navigationItem.leftBarButtonItem = backButton
self.collectionView?.register(CommentCell.self, forCellWithReuseIdentifier: cellID)
collectionView?.scrollIndicatorInsets = UIEdgeInsets(top: 0, left: 0, bottom:-50, right: 0)
collectionView?.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: -50, right: 0)
collectionView?.alwaysBounceVertical = true
collectionView?.keyboardDismissMode = .interactive
setupKeyboardObserver()
view.addSubview(containerView)
view.addConstraintsWithFormat("H:|[v0]|", views: containerView)
view.addConstraintsWithFormat("V:[v0(48)]", views: containerView)
Here im setting the constant to 0
let bottomConstraint = NSLayoutConstraint(item: containerView, attribute: .bottom, relatedBy: .equal, toItem: view, attribute: .bottom, multiplier: 1, constant: 0)
view.addConstraint(bottomConstraint)
NotificationCenter.default.addObserver(self, selector: #selector(handleKeyboardNotification), name: NSNotification.Name.UIKeyboardWillShow, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(handleKeyboardNotification), name: NSNotification.Name.UIKeyboardWillHide, object: nil)
// Register cell classes
// self.collectionView!.register(UICollectionViewCell.self, forCellWithReuseIdentifier: cellID)
fetchComments()
}
Here im taking control of constant and making it react to the keyboard height
func handleKeyboardNotification(notification: NSNotification){
if let userinfo = notification.userInfo{
let keyboardFrame = (userinfo[UIKeyboardFrameEndUserInfoKey] as AnyObject).cgRectValue
bottomConstraint?.constant = -(keyboardFrame?.height)!
let isKeyboardShowing = notification.name == NSNotification.Name.UIKeyboardWillShow
bottomConstraint?.constant = isKeyboardShowing ? CGFloat(-(keyboardFrame?.height)!) : CGFloat(0)
}
}
Despite all this, the keyboard still covers the container view. WHen I change the constant manually it moves but these functions seem to have no effect at dynamically moving the view. I'm confused and any help will be rewarded with a shot at the WWE championship belt. No but seriously I would appreciate the help

What I am able to observe from your code is you are managing the scroll top to down and vice versa with single method you just need to do that with individual method one is while keyboard is appear and another one is while the keyboard is dismiss
Here is the sample snippet which may help you
add the different selector for each notification
NotificationCenter.default.addObserver(self, selector: #selector(self.keyboardWillShow), name: NSNotification.Name.UIKeyboardWillShow, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(self.keyboardWillHide), name: NSNotification.Name.UIKeyboardWillHide, object: nil)
Handle the keyboard appear and disappear event with following method
func keyboardWillShow(notification: NSNotification) {
if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue {
if self.view.frame.origin.y == 0{
UIView.animate(withDuration: 0.1, animations: { () -> Void in
self.view.frame.origin.y -= keyboardSize.height
})
}
}
}
func keyboardWillHide(notification: NSNotification) {
if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue {
if self.view.frame.origin.y != 0{
UIView.animate(withDuration: 0.1, animations: { () -> Void in
self.view.frame.origin.y += keyboardSize.height
})
}
}
}
Note:
Do not forgot to remove Observer while your view is going to disappear like
NotificationCenter.default.removeObserver(self, name: NSNotification.Name.UIKeyboardWillShow, object: nil)
NotificationCenter.default.removeObserver(self, name: NSNotification.Name.UIKeyboardWillHide, object: nil)

Your handleKeyboardNotification function is setting the constant back to 0 in the last line of the function.
Also, your constant shouldn't be negative keyboard value, it should be the height of the keyboard plus a margin if you need it.

Fixed it by changing bottomConstraint from let to var. Forgot let makes it immutable. Haha guess I'm the WWE champion

Related

Why in iOS14 (or at least iOS14.4) keyboardWillShowNotification is fired twice, while in iOS13 only one?

Why in iOS14 (or at least iOS14.4 iPhone 12 simulator) keyboardWillShowNotification is fired twice, while in iOS13 only once?
My final goal is to make visible textfields that are hidden by the keyboard.
This is making my form to misbehave on iOS14 if I follow these steps:
Tap on the top most text field.
Scroll to the bottom.
Tap in the last text field.
Notice that the view is scrolled up to the previous tapped text field (in this case the top most one).
UI:
Code:
class ViewController: UIViewController {
#IBOutlet weak var scrollView: UIScrollView!
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
register()
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
unregister()
}
func register() {
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow(notification:)),
name: UIResponder.keyboardWillShowNotification,
object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide(notification:)),
name: UIResponder.keyboardWillHideNotification,
object: nil)
}
func unregister() {
NotificationCenter.default.removeObserver(self, name: UIResponder.keyboardWillShowNotification, object: nil)
NotificationCenter.default.removeObserver(self, name: UIResponder.keyboardWillHideNotification, object: nil)
}
#objc func keyboardWillShow(notification: NSNotification) {
let keyboardFrame = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect)
let keyboardSize = keyboardFrame?.size
print("keyboardWillShow " + String(describing: keyboardSize))
let contentInsets = UIEdgeInsets(top: 0.0, left: 0.0, bottom: keyboardSize!.height, right: 0.0)
scrollView.contentInset = contentInsets
scrollView.scrollIndicatorInsets = contentInsets
}
#objc func keyboardWillHide(notification: NSNotification) {
print("keyboardWillHide")
let contentInsets = UIEdgeInsets(top: 0.0, left: 0.0, bottom: 0.0, right: 0.0)
scrollView.contentInset = contentInsets
scrollView.scrollIndicatorInsets = contentInsets
}
}
Output:
keyboardWillShow Optional((390.0, 336.0))
keyboardWillShow Optional((390.0, 336.0))
keyboardWillShow Optional((390.0, 336.0))
First output is when I tap the top most textfield.
Outputs 2 and 3 are when I tap the textfield at the bottom. Within these 2, the first one corresponds to the top most textfield and the second one to the textfield at the bottom.
And the scroll is automatically scroll to the the top most textfield instead of just not scroll at all because user had tapped the the textfield at the bottom.
There appears to be a bug (or two) in iOS 14 (I'm testing on 14.3).
Try this for an example - it adds a full-size scroll view containing a vertical stack view with 8 text fields spaced 75-pts apart:
class KeyBoardTestViewController: UIViewController {
let scrollView = UIScrollView()
override func viewDidLoad() {
super.viewDidLoad()
let stack = UIStackView()
stack.axis = .vertical
stack.spacing = 75
scrollView.translatesAutoresizingMaskIntoConstraints = false
stack.translatesAutoresizingMaskIntoConstraints = false
let safeG = view.safeAreaLayoutGuide
let contentG = scrollView.contentLayoutGuide
scrollView.addSubview(stack)
view.addSubview(scrollView)
NSLayoutConstraint.activate([
scrollView.topAnchor.constraint(equalTo: safeG.topAnchor),
scrollView.leadingAnchor.constraint(equalTo: safeG.leadingAnchor),
scrollView.trailingAnchor.constraint(equalTo: safeG.trailingAnchor),
scrollView.bottomAnchor.constraint(equalTo: safeG.bottomAnchor),
stack.topAnchor.constraint(equalTo: contentG.topAnchor, constant: 20.0),
stack.leadingAnchor.constraint(equalTo: contentG.leadingAnchor, constant: 20.0),
stack.trailingAnchor.constraint(equalTo: contentG.trailingAnchor, constant: 20.0),
stack.bottomAnchor.constraint(equalTo: contentG.bottomAnchor, constant: -20.0),
stack.widthAnchor.constraint(equalToConstant: 200.0),
])
for i in 1...8 {
let tf = UITextField()
tf.borderStyle = .roundedRect
tf.text = "\(i)"
stack.addArrangedSubview(tf)
}
}
}
Notice there is no keyboard show/hide handling.
When you run that, tap in the top text field (with a "1" in it). The keyboard will show.
Now, without typing anything, scroll down... because we didn't adjust the scroll view's content inset, you'll only be able to scroll down to the 5th or 6th text field.
Tap in the lowest visible text field --- and the scroll view will scroll so the top text field is again visible, while "text field 5" is still the first responder.
If you scroll / tap / scroll / tap... the keyboard will remain visible but the previous first-responder text field will be scrolled into view.
However, as soon as you type anything in a field, everything returns to normal.
Now, we'll use that same class, but we'll add keyboard notification handling:
class KeyBoardTestViewController: UIViewController {
let scrollView = UIScrollView()
var firstTextField: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
let stack = UIStackView()
stack.axis = .vertical
stack.spacing = 75
scrollView.translatesAutoresizingMaskIntoConstraints = false
stack.translatesAutoresizingMaskIntoConstraints = false
let safeG = view.safeAreaLayoutGuide
let contentG = scrollView.contentLayoutGuide
scrollView.addSubview(stack)
view.addSubview(scrollView)
NSLayoutConstraint.activate([
scrollView.topAnchor.constraint(equalTo: safeG.topAnchor),
scrollView.leadingAnchor.constraint(equalTo: safeG.leadingAnchor),
scrollView.trailingAnchor.constraint(equalTo: safeG.trailingAnchor),
scrollView.bottomAnchor.constraint(equalTo: safeG.bottomAnchor),
stack.topAnchor.constraint(equalTo: contentG.topAnchor, constant: 20.0),
stack.leadingAnchor.constraint(equalTo: contentG.leadingAnchor, constant: 20.0),
stack.trailingAnchor.constraint(equalTo: contentG.trailingAnchor, constant: 20.0),
stack.bottomAnchor.constraint(equalTo: contentG.bottomAnchor, constant: -20.0),
stack.widthAnchor.constraint(equalToConstant: 200.0),
])
for i in 1...8 {
let tf = UITextField()
tf.borderStyle = .roundedRect
tf.text = "\(i)"
stack.addArrangedSubview(tf)
if i == 1 {
firstTextField = tf
}
}
register()
}
func register() {
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow(notification:)),
name: UIResponder.keyboardWillShowNotification,
object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide(notification:)),
name: UIResponder.keyboardWillHideNotification,
object: nil)
}
#objc func keyboardWillShow(notification: NSNotification) {
let keyboardFrame = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect)
let keyboardSize = keyboardFrame?.size
print("keyboardWillShow " + String(describing: keyboardSize))
// only change scroll view insets if .bottom != keyboard height
if scrollView.contentInset.bottom != keyboardSize?.height {
print("setting insets")
let contentInsets = UIEdgeInsets(top: 0.0, left: 0.0, bottom: keyboardSize!.height, right: 0.0)
scrollView.contentInset = contentInsets
scrollView.scrollIndicatorInsets = contentInsets
}
}
#objc func keyboardWillHide(notification: NSNotification) {
print("keyboardWillHide")
let contentInsets = UIEdgeInsets(top: 0.0, left: 0.0, bottom: 0.0, right: 0.0)
scrollView.contentInset = contentInsets
scrollView.scrollIndicatorInsets = contentInsets
}
}
We'll see the same (buggy) behavior... and we'll see the "double will show" notification firing. I added an if clause so we only change the content inset if the keyboard frame has changed, so we have ruled that out as the culprit.
Again, though, as soon as we type a character into any of the text fields, the expected behavior returns to normal -- AND we no longer get the "double will show" notifications.
Unfortunately, after trying several different things to force it, I haven't found a work-around :(
Ok, thanks guys for your attention.
What we resolved, to minimise this behaviour, is to set the scroll view to dismiss the KB on drag. This will move the "double call" to the keyboard is hidden and not when it is shown.

How I get the keyboard frame before the keyboard appears

I have a button where you get a textfield with a keyboard. At the moment, when I get this textfield, the textfield is in the left corner and the textfield appears. How can I handle this, that the textfield is above my keyboard?
The problem is, that I get the keyboard height after the code in editTextButtonTapped is done. How can I get the height of the keyboard before editTextButtonTapped is called?
// This are my global Variables to create the textfield
var myTextField: UITextField = UITextField(frame: CGRect(x: 0,y: 0, width: 0, height:0))
var firstkeyboardHeight = CGFloat()
NotificationCenter.default.addObserver(self, selector: #selector(keyboardDidShow(_:)), name: UIResponder.keyboardWillShowNotification, object: nil)
#objc func keyboardWillShow(_ notification: NSNotification) -> Void {
if let keyboardRect = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as AnyObject).cgRectValue {
let keyboardHeight = keyboardRect.height
firstkeyboardHeight = keyboardHeight
}
}
#IBAction func editTextButtonTapped(_ sender: UIButton) {
myTextField.becomeFirstResponder()
self.myTextField = UITextField(frame: CGRect(x: 0,y: self.firstkeyboardHeight, width: self.view.frame.width, height: 50.0))
self.myTextField.backgroundColor = .green
self.Gestures(addGesture: self.myTextField)
self.view.addSubview(self.myTextField)
}
There is only this set of notifications:
[ UIResponder.keyboardWillShowNotification, UIResponder.keyboardWillHideNotification, UIResponder.keyboardDidShowNotification, UIResponder.keyboardDidHideNotification]
Only inside can obtain the frame values:
NotificationCenter.default.addObserver(forName: UIResponder.keyboardWillHideNotification,
object: nil,
queue: .main) { [weak self] notification in
guard let userInfo = notification.userInfo else {
return
}
let initialValue = userInfo[UIResponder.keyboardFrameBeginUserInfoKey] as? NSValue,
let finalValue = userInfo[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue,
let durationValue = userInfo[UIResponder.keyboardAnimationDurationUserInfoKey] as? NSNumber,
let curveValue = userInfo[UIResponder.keyboardAnimationCurveUserInfoKey] as? NSNumber
}
So, I don't think that there are any possible allowed ways.
You have several ways to do that. In either case I'd avoid recreating the textfield every time.
let myTextField: UITextField = {
let textfield = UITextField()
textfield.translatesAutoresizingMaskIntoConstraints = false
textfield.backgroundColor = .green
textfield.isHidden = true
return textfield
}()
var bottomConstraint: NSLayoutConstraint?
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(myTextField)
let bottomConstraint = myTextField.bottomAnchor.constraint(equalTo: view.bottomAnchor)
NSLayoutConstraint.activate([
myTextField.leadingAnchor.constraint(equalTo: view.leadingAnchor),
myTextField.trailingAnchor.constraint(equalTo: view.trailingAnchor),
myTextField.heightAnchor.constraint(equalToConstant: 50),
bottomConstraint
])
self.bottomConstraint = bottomConstraint
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow(_:)), name: UIResponder.keyboardWillShowNotification, object: nil)
}
#objc func keyboardWillShow(_ notification: NSNotification) -> Void {
guard let keyboardFrame = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue else { return }
bottomConstraint?.constant = -keyboardFrame.height
}
#IBAction func editTextButtonTapped(_ sender: UIButton) {
myTextField.becomeFirstResponder()
myTextField.isHidden = false
}

Can you set contentInset more than once?

I have a tableview with table cells. Each cell has a textfield. I have the following code to prevent the bottom few cells from being blocked by the keyboard
#objc func keyboardWillShow(_ notification:Notification) {
if let keyboardSize = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue {
tableView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: keyboardSize.height, right: 0)
}
}
#objc func keyboardWillHide(notification: NSNotification) {
tableView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
}
override func viewDidLoad() {
super.viewDidLoad()
NotificationCenter.default.addObserver(self, selector: #selector(TransactionViewController.keyboardWillHide), name: UIApplication.keyboardWillChangeFrameNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(TransactionViewController.keyboardWillShow), name: UIApplication.keyboardWillChangeFrameNotification, object: nil)
}
The keyboardWillHide function works as expected. However, when the keyboard is hidden, the table does bounce back down the the bottom, resulting in no extra whitespace being shown (which is what I want). What I don't like is how you can still scroll down on the table to the contentInset from where the keyboard was first shown. Is there a way to make it so that after the keyboard disappears, that you can't scroll down passed the bottom of the table?
Replace
keyboardFrameBeginUserInfoKey
with
keyboardFrameEndUserInfoKey
#objc func keyboardWillShow(_ notification:Notification) {
if let keyboardSize = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue {
tableView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: keyboardSize.height, right: 0)
}
}
#objc func keyboardWillHide(notification: NSNotification) {
tableView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
}
override func viewDidLoad() {
super.viewDidLoad()
NotificationCenter.default.addObserver(self, selector: #selector(TransactionViewController.keyboardWillHide), name: UIApplication.keyboardWillHideNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(TransactionViewController.keyboardWillShow), name: UIApplication.keyboardWillShowNotification, object: nil)
}

Label is attached to the keyboard

How to add a block with the send button so that it moves with the keyboard. And also that would be textview behaved the same.
preview
Add this code in your controller
func createInputAccessoryView () -> UIToolbar {
let toolbarAccessoryView = UIToolbar(frame: CGRect(x: 0, y: 0, width: self.view.bounds.size.width, height: 44))
toolbarAccessoryView.barStyle = .default
toolbarAccessoryView.tintColor = UIColor.blue
let flexSpace = UIBarButtonItem(barButtonSystemItem:.flexibleSpace, target:nil, action:nil)
let doneButton = UIBarButtonItem(barButtonSystemItem:.done, target:self, action:Selector(("doneTouched")))
toolbarAccessoryView.setItems([flexSpace, doneButton], animated: false)
return toolbarAccessoryView
}
#objc func doneTouched() {
/* Your action goes here */
}
Now add this in your viewDidLoad or anywhere
yourTextView.inputAccessoryView = createInputAccessoryView ()
Design the block view and then attach it's bottom constraint as IBOutlet and do this
override func viewDidLoad() {
super.viewDidLoad()
NotificationCenter.default.addObserver(self, selector: #selector(ViewController.keyboardWillShow), name: NSNotification.Name.UIKeyboardWillShow, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(ViewController.keyboardWillHide), name: NSNotification.Name.UIKeyboardWillHide, object: nil)
}
#objc func keyboardWillShow(notification: NSNotification) {
if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue {
self.viewBotCon.constant = -1 * keyboardSize.height
self.view.layoutIfNeeded()
}
}
#objc func keyboardWillHide(notification: NSNotification) {
self.viewBotCon.constant = 0
self.view.layoutIfNeeded()
}

While typing on keyboard button tap doesn't get recognized

I've got a problem with my iOS application. I want to implement something like a MessagingViewController where you got a UITextView and Button (sendButton) below an UITableView. If a tap the textView, the keyboard appears, the View goes up.. so far so good.
But, if I am entering random text and tab/press the send button (independent of what should happen now) while typing or if the time gap between typing and Button tab is to small, the tap doesn't get recognized. If you try iMessage or WhatsApp this isn't a problem.
I don't know what to do, I also tried CocoaPods like SlackViewController or InputAccessoryView but it is always the same problem. While typing, the button tap doesn't get recognized. I tried it with the normal IBAction of a UIButton and UITapGestureRecognizer.
I hope somebody can help me, this problem makes the UX horrible.
Thanks a lot!!!
Edit: Here's an example where the Button is in an InputAccessoryView.
import UIKit
class MessagingViewController: UIViewController, UITableViewDataSource {
var messages: [String] = ["12", "32"]
var accessory: UIView!
var cancelButton: UIButton!
var charactersLeftLabel: UILabel!
var sendButton: UIButton!
#IBOutlet var tableView: UITableView!
#IBOutlet var messagesTextView: UITextView!
override func viewDidLoad() {
super.viewDidLoad()
tableView.dataSource = self
tableView.register(UINib(nibName: TableViewCell.className, bundle:nil),
forCellReuseIdentifier: TableViewCell.className)
addAccessoryView()
NotificationCenter.default.addObserver(self, selector: #selector(MessagingViewController.keyboardWillShow), name: NSNotification.Name.UIKeyboardWillShow, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(MessagingViewController.keyboardWillHide), name: NSNotification.Name.UIKeyboardWillHide, object: nil)
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return messages.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "TableViewCell", for: indexPath) as? TableViewCell
cell?.titleLabel.text = "Sender: \(indexPath.row): "
cell?.detailLabel.text = messages[indexPath.row]
return cell!
}
func addAccessoryView() {
let frame = CGRect(x:0, y:0, width: self.view.frame.width,height: 45)
accessory = UIView(frame: frame)
accessory.backgroundColor = UIColor.lightGray
accessory.alpha = 0.6
accessory.translatesAutoresizingMaskIntoConstraints = false
self.messagesTextView.inputAccessoryView = accessory
sendButton = UIButton(type: .custom)
sendButton.setTitleColor(UIColor.red, for: .normal)
sendButton.setTitle("Send", for: .normal)
sendButton.setTitleColor(UIColor.white, for: .disabled)
sendButton.addTarget(self, action: #selector(MessagingViewController.sendButtonTapped(_:)), for: .touchUpInside)
sendButton.showsTouchWhenHighlighted = true
sendButton.isEnabled = true
sendButton.translatesAutoresizingMaskIntoConstraints = false
accessory.addSubview(sendButton)
let sendTrailingConstraint = NSLayoutConstraint(item: sendButton, attribute: .trailing, relatedBy: .equal, toItem: accessory, attribute: .trailing, multiplier: 1.0, constant: -20)
accessory.addConstraint(sendTrailingConstraint)
let sendCenterYConstraint = NSLayoutConstraint(item: sendButton, attribute: .centerY, relatedBy: .equal, toItem: accessory, attribute: .centerY, multiplier: 1.0, constant: 0)
accessory.addConstraint(sendCenterYConstraint)
}
func sendButtonTapped(_ sender: UIButton) {
messages.append(messagesTextView.text)
messagesTextView.text.removeAll()
tableView.reloadData()
tableView.scrollToRow(at: IndexPath(row: messages.count - 1, section: 0), at: .bottom, animated: true)
}
func keyboardWillShow(notification: NSNotification) {
if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue {
if self.view.frame.origin.y == 0{
self.view.frame.origin.y -= keyboardSize.height
}
}
}
func keyboardWillHide(notification: NSNotification) {
if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue {
if self.view.frame.origin.y != 0{
self.view.frame.origin.y += keyboardSize.height
}
}
}
}
I just tested on my project, it's works without any problem, add your code to see what you did. (i can't comment so i put this as an answer)

Resources