-
Notifications
You must be signed in to change notification settings - Fork 7
/
FormViewController.swift
executable file
·57 lines (39 loc) · 1.76 KB
/
FormViewController.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//
// FormViewController.swift
// NMG.CRM
//
// Created by soyombo bat-erdene on 4/6/18.
// Copyright © 2018 soyombo bat-erdene. All rights reserved.
//
import UIKit
class FormViewController: UIViewController {
let scrollView = UIScrollView()
override func viewDidLoad() {
super.viewDidLoad()
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)
scrollView.frame = CGRect(x: 0, y: 0, width: view.frame.width, height: view.frame.height)
scrollView.contentSize = CGSize(width: view.frame.width, height: view.frame.height)
view.addSubview(scrollView)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
deinit{
NotificationCenter.default.removeObserver(self)
}
@objc func dismissKeyboard(){
self.view.endEditing(true)
}
@objc func keyboardWillShow(notification: NSNotification) {
if let keyboardSize = (notification.userInfo?[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue {
let contentInsets = UIEdgeInsets(top: 0, left: 0, bottom: keyboardSize.height, right: 0)
scrollView.contentInset = contentInsets
}
}
@objc func keyboardWillHide(notification: NSNotification) {
let contentInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
scrollView.contentInset = contentInsets
}
}