Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import UIKit
- class ViewController: UIViewController {
- let sharedInstance = Note()
- @IBOutlet weak var heightScrollView: NSLayoutConstraint!
- @IBOutlet weak var scrollView: UIScrollView!
- @IBOutlet weak var titleTextField: UITextField!
- @IBOutlet weak var contentTextView: UITextView!
- @IBAction func useDestroyDateSwitcher(_ sender: UISwitch) {
- // let switcher = UIDatePicker()
- //
- }
- @objc func keyboardWillChange(notification: Notification) {
- guard let keyboardRect = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue else {
- return
- }
- if notification.name == UIResponder.keyboardWillShowNotification || notification.name == UIResponder.keyboardWillChangeFrameNotification {
- let keyboardHeight: CGFloat = CGFloat(keyboardRect.height)
- let scrollViewHeight: CGFloat = CGFloat(heightScrollView.constant)
- var frame = scrollViewHeight - keyboardHeight
- scrollView.contentSize.height = frame
- }
- else {
- scrollView.frame.origin.y = 0
- }
- }
- func autoSizeTextView() {
- var frame = self.contentTextView.frame
- frame.size.height = self.contentTextView.contentSize.height
- self.contentTextView.frame = frame
- }
- override func viewDidLoad() {
- super.viewDidLoad()
- NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillChange(notification:)), name: UIResponder.keyboardWillShowNotification, object: nil)
- NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillChange(notification:)), name: UIResponder.keyboardWillHideNotification, object: nil)
- NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillChange(notification:)), name: UIResponder.keyboardWillChangeFrameNotification, object: nil)
- }
- deinit {
- NotificationCenter.default.removeObserver(self, name: UIResponder.keyboardWillShowNotification, object: nil)
- NotificationCenter.default.removeObserver(self, name: UIResponder.keyboardWillHideNotification, object: nil)
- NotificationCenter.default.removeObserver(self, name: UIResponder.keyboardWillChangeFrameNotification, object: nil)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement