Showing
5 changed files
with
222 additions
and
29 deletions
... | ... | @@ -7,17 +7,31 @@ |
7 | 7 | |
8 | 8 | import UIKit |
9 | 9 | |
10 | +protocol ViewDelegate: AnyObject { | |
11 | + func viewDidTapImage() | |
12 | +} | |
13 | + | |
10 | 14 | class AddResidentsView: UIView { |
15 | + var isShow: Bool = false | |
16 | + | |
17 | + weak var delegate: ViewDelegate? | |
18 | + | |
11 | 19 | let blurEffect: UIVisualEffectView = { |
12 | 20 | let blur = UIBlurEffect(style: UIBlurEffect.Style.systemMaterialDark) |
13 | 21 | let obj = UIVisualEffectView(effect: blur) |
14 | 22 | obj.autoresizingMask = [.flexibleWidth, .flexibleHeight] |
15 | 23 | obj.alpha = 0.9 |
24 | + obj.isUserInteractionEnabled = true | |
16 | 25 | return obj |
17 | 26 | }() |
18 | 27 | |
19 | - var transparentView: UIView = { | |
28 | + lazy var transparentView: UIView = { | |
20 | 29 | var obj = UIView() |
30 | + obj.isUserInteractionEnabled = true | |
31 | + var tap = UIGestureRecognizer(target: self, action: #selector(imageTapped)) | |
32 | + obj.addGestureRecognizer(tap) | |
33 | + obj.backgroundColor = .black | |
34 | + obj.alpha = 0.5 | |
21 | 35 | return obj |
22 | 36 | }() |
23 | 37 | |
... | ... | @@ -32,7 +46,7 @@ class AddResidentsView: UIView { |
32 | 46 | var addResidentLabeL: UILabel = { |
33 | 47 | var obj = UILabel() |
34 | 48 | obj.text = "Add resident" |
35 | - obj.textColor = UIColor(red: 0.196, green: 0.216, blue: 0.333, alpha: 1) | |
49 | + obj.textColor = .TextColor.darkBlue | |
36 | 50 | obj.font = .skModernist(type: .bold, ofSize: 24) |
37 | 51 | return obj |
38 | 52 | }() |
... | ... | @@ -41,14 +55,14 @@ class AddResidentsView: UIView { |
41 | 55 | var obj = UIButton() |
42 | 56 | obj.layer.cornerRadius = 13 |
43 | 57 | obj.layer.borderWidth = 1 |
44 | - obj.layer.borderColor = UIColor(red: 0.882, green: 0.91, blue: 0.91, alpha: 1).cgColor | |
58 | + obj.layer.borderColor = .ButtonBorderColor.lightGrey | |
45 | 59 | obj.setImage(UIImage(named: "Close"), for: .normal) |
46 | 60 | return obj |
47 | 61 | }() |
48 | 62 | |
49 | 63 | var dividingLineView: UIView = { |
50 | 64 | var view = UIView() |
51 | - view.backgroundColor = UIColor(red: 246/255, green: 246/255, blue: 246/255, alpha: 1) | |
65 | + view.backgroundColor = MyColor.dividingLineBackgroundColor.value | |
52 | 66 | return view |
53 | 67 | }() |
54 | 68 | |
... | ... | @@ -56,15 +70,18 @@ class AddResidentsView: UIView { |
56 | 70 | var obj = UILabel() |
57 | 71 | obj.text = "Resident name" |
58 | 72 | obj.font = .skModernist(type: .bold, ofSize: 14) |
59 | - obj.textColor = UIColor(red: 0.196, green: 0.216, blue: 0.333, alpha: 1) | |
73 | + obj.textColor = .TextColor.darkBlue | |
60 | 74 | return obj |
61 | 75 | }() |
62 | 76 | |
63 | - var nameTextField: UITextField = { | |
64 | - var obj = UITextField() | |
65 | - obj.backgroundColor = UIColor(red: 0.954, green: 0.954, blue: 0.954, alpha: 1) | |
77 | + var nameTextField: TextFieldWithPadding = { | |
78 | + var obj = TextFieldWithPadding() | |
79 | + obj.backgroundColor = .TextFieldColor.general | |
66 | 80 | obj.textAlignment = .left |
67 | 81 | obj.layer.cornerRadius = 15 |
82 | + obj.placeholder = "Enter resident name" | |
83 | + obj.font = .skModernist(type: .regular, ofSize: 14) | |
84 | + obj.textPadding = UIEdgeInsets(top: 0, left: 22, bottom: 0, right: 22) | |
68 | 85 | return obj |
69 | 86 | }() |
70 | 87 | |
... | ... | @@ -72,27 +89,36 @@ class AddResidentsView: UIView { |
72 | 89 | var obj = UILabel() |
73 | 90 | obj.text = "Mobile number" |
74 | 91 | obj.font = .skModernist(type: .bold, ofSize: 14) |
75 | - obj.textColor = UIColor(red: 0.196, green: 0.216, blue: 0.333, alpha: 1) | |
92 | + obj.textColor = MyColor.darkBlueTextColor.value | |
76 | 93 | return obj |
77 | 94 | }() |
78 | 95 | |
79 | - var mobileNumberTextField: UITextField = { | |
80 | - var obj = UITextField() | |
81 | - obj.backgroundColor = UIColor(red: 0.954, green: 0.954, blue: 0.954, alpha: 1) | |
96 | + var mobileNumberTextField: TextFieldWithPadding = { | |
97 | + var obj = TextFieldWithPadding() | |
98 | + obj.backgroundColor = MyColor.generalTextFieldBackgroundColor.value | |
82 | 99 | obj.textAlignment = .left |
83 | 100 | obj.layer.cornerRadius = 15 |
101 | + obj.font = .skModernist(type: .regular, ofSize: 14) | |
102 | + obj.textPadding = UIEdgeInsets(top: 0, left: 22, bottom: 0, right: 45) | |
103 | + obj.placeholder = "Enter resident number" | |
84 | 104 | return obj |
85 | 105 | }() |
86 | - | |
87 | - var managerButton: UIButton = { | |
88 | - var obj = UIButton() | |
89 | - obj.setImage(UIImage(named: ""), for: .normal) | |
90 | - obj.setImage(UIImage(named: ""), for: .selected) | |
106 | + | |
107 | + let contactListButton: UIButton = { | |
108 | + let obj = UIButton() | |
109 | + obj.setImage(UIImage(named:"3Users"), for: .normal) | |
91 | 110 | return obj |
92 | 111 | }() |
93 | 112 | |
94 | - var hiddenButton: UIButton = { | |
95 | - var obj = UIButton() | |
113 | + var managerButton: SquereCheckbox = { | |
114 | + var obj = SquereCheckbox() | |
115 | + obj.checkboxTitle = "Manager" | |
116 | + return obj | |
117 | + }() | |
118 | + | |
119 | + var hiddenButton: SquereCheckbox = { | |
120 | + var obj = SquereCheckbox() | |
121 | + obj.checkboxTitle = "Hidden" | |
96 | 122 | return obj |
97 | 123 | }() |
98 | 124 | |
... | ... | @@ -118,7 +144,6 @@ class AddResidentsView: UIView { |
118 | 144 | obj.setTitle("Add resident", for: .normal) |
119 | 145 | obj.setTitleColor(UIColor(red: 1, green: 1, blue: 1, alpha: 1), for: .normal) |
120 | 146 | obj.titleLabel?.font = .skModernist(type: .bold, ofSize: 16) |
121 | - obj.setTitleColor(.cyan, for: .normal) | |
122 | 147 | obj.clipsToBounds = true |
123 | 148 | obj.layer.masksToBounds = true |
124 | 149 | return obj |
... | ... | @@ -135,6 +160,7 @@ class AddResidentsView: UIView { |
135 | 160 | } |
136 | 161 | |
137 | 162 | func layout() { |
163 | + isUserInteractionEnabled = true | |
138 | 164 | addResidentButton.layer.insertSublayer(gradientBG, at: 0) |
139 | 165 | |
140 | 166 | addSubview(transparentView) |
... | ... | @@ -148,6 +174,8 @@ class AddResidentsView: UIView { |
148 | 174 | containerView.addSubview(nameTextField) |
149 | 175 | containerView.addSubview(mobileNumberLabel) |
150 | 176 | containerView.addSubview(mobileNumberTextField) |
177 | + mobileNumberTextField.addSubview(contactListButton) | |
178 | + | |
151 | 179 | containerView.addSubview(managerButton) |
152 | 180 | containerView.addSubview(hiddenButton) |
153 | 181 | containerView.addSubview(heartButton) |
... | ... | @@ -159,9 +187,7 @@ class AddResidentsView: UIView { |
159 | 187 | |
160 | 188 | containerView.snp.makeConstraints { |
161 | 189 | $0.leading.trailing.equalToSuperview().inset(25) |
162 | -// $0.top.equalToSuperview().offset(174) | |
163 | -// $0.bottom.equalToSuperview().offset(-201) | |
164 | - $0.centerY.equalToSuperview() | |
190 | + $0.centerY.equalTo(transparentView.snp.centerY) | |
165 | 191 | } |
166 | 192 | |
167 | 193 | addResidentLabeL.snp.makeConstraints { |
... | ... | @@ -184,7 +210,6 @@ class AddResidentsView: UIView { |
184 | 210 | residentNameLabel.snp.makeConstraints { |
185 | 211 | $0.top.equalTo(dividingLineView.snp.bottom).offset(24) |
186 | 212 | $0.leading.equalToSuperview().offset(44) |
187 | - | |
188 | 213 | } |
189 | 214 | |
190 | 215 | nameTextField.snp.makeConstraints { |
... | ... | @@ -196,7 +221,6 @@ class AddResidentsView: UIView { |
196 | 221 | mobileNumberLabel.snp.makeConstraints { |
197 | 222 | $0.leading.equalTo(residentNameLabel.snp.leading) |
198 | 223 | $0.top.equalTo(nameTextField.snp.bottom).offset(15) |
199 | - | |
200 | 224 | } |
201 | 225 | |
202 | 226 | mobileNumberTextField.snp.makeConstraints { |
... | ... | @@ -205,14 +229,22 @@ class AddResidentsView: UIView { |
205 | 229 | $0.height.equalTo(47) |
206 | 230 | } |
207 | 231 | |
232 | + contactListButton.snp.makeConstraints { | |
233 | + $0.height.width.equalTo(24) | |
234 | + $0.centerY.equalToSuperview() | |
235 | + $0.trailing.equalToSuperview().offset(-19) | |
236 | + } | |
237 | + | |
208 | 238 | managerButton.snp.makeConstraints { |
209 | 239 | $0.leading.equalToSuperview().offset(29) |
210 | 240 | $0.top.equalTo(mobileNumberTextField.snp.bottom).offset(30) |
241 | + $0.height.equalTo(20) | |
211 | 242 | } |
212 | 243 | |
213 | 244 | hiddenButton.snp.makeConstraints { |
214 | 245 | $0.top.equalTo(managerButton) |
215 | 246 | $0.leading.equalTo(managerButton.snp.trailing).offset(24) |
247 | + $0.height.equalTo(20) | |
216 | 248 | } |
217 | 249 | |
218 | 250 | heartButton.snp.makeConstraints { |
... | ... | @@ -223,7 +255,7 @@ class AddResidentsView: UIView { |
223 | 255 | addResidentButton.snp.makeConstraints { |
224 | 256 | $0.top.equalTo(managerButton.snp.bottom).offset(43) |
225 | 257 | $0.leading.trailing.bottom.equalToSuperview() |
226 | - $0.height.equalTo(45) | |
258 | + $0.height.equalTo(64) | |
227 | 259 | } |
228 | 260 | } |
229 | 261 | |
... | ... | @@ -232,4 +264,8 @@ class AddResidentsView: UIView { |
232 | 264 | gradientBG.frame = addResidentButton.bounds |
233 | 265 | blurEffect.frame = transparentView.bounds |
234 | 266 | } |
267 | + | |
268 | + @objc func imageTapped() { | |
269 | + delegate?.viewDidTapImage() | |
270 | + } | |
235 | 271 | } | ... | ... |
... | ... | @@ -6,8 +6,19 @@ |
6 | 6 | // |
7 | 7 | |
8 | 8 | import UIKit |
9 | +import ContactsUI | |
9 | 10 | |
10 | -class AddResidentsViewController: UIViewController { | |
11 | +class AddResidentsViewController: UIViewController, ViewDelegate { | |
12 | + var myData: ResidentModel? | |
13 | + | |
14 | + var savedResidents: [ResidentModel] = [] | |
15 | + | |
16 | + weak var delegate: ResidentSavable? | |
17 | + | |
18 | + var contact = ContactPickerViewController() | |
19 | + | |
20 | + var isKeyboardAppear = false | |
21 | + | |
11 | 22 | var mainView = AddResidentsView() |
12 | 23 | |
13 | 24 | override func loadView() { |
... | ... | @@ -15,10 +26,136 @@ class AddResidentsViewController: UIViewController { |
15 | 26 | } |
16 | 27 | |
17 | 28 | override func viewDidLoad() { |
29 | + super.viewDidLoad() | |
30 | + initViewController() | |
31 | + } | |
32 | + | |
33 | + func initViewController() { | |
18 | 34 | mainView.closeButton.addTarget(self, action: #selector(didTapCloseButton), for: .touchUpInside) |
35 | + mainView.managerButton.addTarget(self, action: #selector(didTapOnChangeableButtons(_:)), for: .touchUpInside) | |
36 | + mainView.hiddenButton.addTarget(self, action: #selector(didTapOnChangeableButtons(_:)), for: .touchUpInside) | |
37 | + mainView.heartButton.addTarget(self, action: #selector(didTapOnChangeableButtons(_:)), for: .touchUpInside) | |
38 | + mainView.addResidentButton.addTarget(self, action: #selector(didTapResidentButton), for: .touchUpInside) | |
39 | + mainView.contactListButton.addTarget(self, action: #selector(didTapContactListButton), for: .touchUpInside) | |
40 | + | |
41 | + mainView.delegate = self | |
42 | + gestureSetup(mainView.transparentView) | |
43 | + | |
44 | + NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow(notification:)), name: UIResponder.keyboardWillShowNotification, object: nil) | |
45 | + NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide), name: UIResponder.keyboardWillHideNotification, object: nil) | |
46 | + } | |
47 | + | |
48 | + deinit { | |
49 | + NotificationCenter.default.removeObserver(self, name: UIResponder.keyboardWillShowNotification, object: nil) | |
50 | + NotificationCenter.default.removeObserver(self, name: UIResponder.keyboardWillHideNotification, object: nil) | |
19 | 51 | } |
20 | 52 | |
21 | - @objc func didTapCloseButton() { | |
53 | + @objc func viewDidTapImage() { | |
54 | + print("🕵️♂️") | |
55 | + } | |
56 | + | |
57 | + func gestureSetup(_ view: UIView) { | |
58 | + let tapGesture = UIGestureRecognizer() | |
59 | + tapGesture.addTarget(self, action: #selector(gestureFired)) | |
60 | + view.addGestureRecognizer(tapGesture) | |
61 | + view.isUserInteractionEnabled = true | |
62 | + } | |
63 | + | |
64 | + @objc private func gestureFired() { | |
65 | + print("❌") | |
66 | + | |
67 | + } | |
68 | + | |
69 | + func reloadView() { | |
70 | + mainView.mobileNumberTextField.reloadInputViews() | |
71 | + } | |
72 | + | |
73 | + @objc private func didTapCloseButton() { | |
22 | 74 | dismiss(animated: true, completion: nil) |
23 | 75 | } |
76 | + | |
77 | + @objc private func didTapResidentButton() { | |
78 | + print("✅") | |
79 | + didReceiveData() | |
80 | + dismiss(animated: true, completion: nil) | |
81 | + } | |
82 | + | |
83 | + func didReceiveData() { | |
84 | + mainView.nameTextField.text = myData?.name | |
85 | + mainView.mobileNumberTextField.text = myData?.mobileNumber | |
86 | + mainView.managerButton.isSelected = ((myData?.manager) != nil) | |
87 | + mainView.hiddenButton.isSelected = ((myData?.hidden) != nil) | |
88 | + mainView.heartButton.isSelected = ((myData?.hidden) != nil) | |
89 | + | |
90 | + delegate?.save(myData!) | |
91 | + } | |
92 | + | |
93 | + @objc private func didTapOnChangeableButtons(_ sender: SquereCheckbox) { | |
94 | + switch sender { | |
95 | + case mainView.managerButton : | |
96 | + if mainView.managerButton.isSelected == true { | |
97 | + mainView.managerButton.isSelected = false | |
98 | + } else { | |
99 | + mainView.managerButton.isSelected = true | |
100 | + } | |
101 | + case mainView.hiddenButton : | |
102 | + if mainView.hiddenButton.isSelected == true { | |
103 | + mainView.hiddenButton.isSelected = false | |
104 | + } else { | |
105 | + mainView.hiddenButton.isSelected = true | |
106 | + } | |
107 | + case mainView.heartButton : | |
108 | + if mainView.heartButton.isSelected == true { | |
109 | + mainView.heartButton.isSelected = false | |
110 | + } else { | |
111 | + mainView.heartButton.isSelected = true | |
112 | + } | |
113 | + default: | |
114 | + return | |
115 | + } | |
116 | + } | |
117 | + | |
118 | + @objc func didTapContactListButton() { | |
119 | + presentContactPickerVC() | |
120 | + } | |
121 | + | |
122 | + func presentContactPickerVC() { | |
123 | + let viewController = ContactPickerViewController() | |
124 | + present(viewController, animated: true) | |
125 | + } | |
126 | +} | |
127 | + | |
128 | +//MARK: - Keyboard observer | |
129 | +extension AddResidentsViewController { | |
130 | + @objc private func keyboardWillShow(notification: NSNotification) { | |
131 | + let duration = notification.userInfo?[UIResponder.keyboardAnimationDurationUserInfoKey] as? Double | |
132 | + | |
133 | + if !isKeyboardAppear { | |
134 | + | |
135 | + UIView.animate(withDuration: duration ?? 0) { | |
136 | + self.mainView.containerView.snp.updateConstraints { make in | |
137 | + make.centerY.equalTo(self.mainView.transparentView.snp.centerY).offset(-150) | |
138 | + } | |
139 | + self.mainView.layoutIfNeeded() | |
140 | + } | |
141 | + isKeyboardAppear = true | |
142 | + } | |
143 | + } | |
144 | + | |
145 | + @objc private func keyboardWillHide(notification: NSNotification) { | |
146 | + let duration = notification.userInfo?[UIResponder.keyboardAnimationDurationUserInfoKey] as? Double | |
147 | + | |
148 | + if isKeyboardAppear { | |
149 | + | |
150 | + UIView.animate(withDuration: duration ?? 0) { | |
151 | + self.mainView.containerView.snp.updateConstraints { make in | |
152 | + make.centerY.equalTo(self.mainView.transparentView.snp.centerY) | |
153 | + } | |
154 | + self.mainView.layoutIfNeeded() | |
155 | + } | |
156 | + isKeyboardAppear = false | |
157 | + } | |
158 | + } | |
24 | 159 | } |
160 | + | |
161 | + | ... | ... |
Please
register
or
login
to post a comment