-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathSignUpViewController.swift
More file actions
106 lines (78 loc) · 4.07 KB
/
SignUpViewController.swift
File metadata and controls
106 lines (78 loc) · 4.07 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
//
// SignUpViewController.swift
// ManagerExample
//
// Created by Drew Olbrich on 1/10/19.
// Copyright 2019 Oath Inc.
//
// Licensed under the terms of the MIT License. See the file LICENSE for the full terms.
//
import UIKit
import ScrollingContentViewController
/// A class that demonstrates using `ScrollingContentViewManager` in conjunction
/// with an arbitrary `UIViewController` class instead of subclassing
/// `ScrollingContentViewController`.
class SignUpViewController: UIViewController {
private lazy var scrollingContentViewManager = ScrollingContentViewManager(hostViewController: self)
/// Helper object that encapsulates code common to all
/// `ScrollingContentViewController` example applications.
private var signUpController: SignUpController?
@IBOutlet weak var contentView: UIView!
@IBOutlet weak var logoImageView: UIImageView!
@IBOutlet weak var nameTextField: PillTextField!
@IBOutlet weak var emailTextField: PillTextField!
@IBOutlet weak var passwordTextField: PillTextField!
@IBOutlet weak var signUpButton: PillButton!
@IBOutlet weak var signInButton: UIButton!
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
override func loadView() {
// Load all controls and connect all outlets defined by Interface Builder.
super.loadView()
scrollingContentViewManager.loadView(forContentView: contentView)
// Replace the root view with a gradient view.
view = GradientBackgroundView()
}
override func viewDidLoad() {
super.viewDidLoad()
// Set the content view's background color to transparent so the gradient
// background root view can be seen behind it.
contentView.backgroundColor = nil
// When ScrollingContentViewManager.contentView is first assigned, this has the
// side effect of adding a scroll view to the view controller's root view, and
// adding the content view to the scroll view. If a new view was assigned to this
// property later, it would replace the existing content view in the scroll view
// and leave the scroll view unchanged.
scrollingContentViewManager.contentView = contentView
// Allow the content view to shrink vertically when the keyboard is presented.
scrollingContentViewManager.shouldResizeContentViewForKeyboard = true
// Allow the user to dismiss the keyboard by dragging from the scroll view to the
// bottom of the screen.
scrollingContentViewManager.scrollView.keyboardDismissMode = .interactive
signUpController = SignUpController(logoImageView: logoImageView, nameTextField: nameTextField, emailTextField: emailTextField, passwordTextField: passwordTextField, signUpButton: signUpButton, signInButton: signInButton, delegate: self)
}
// Note: This method is not strictly required, but logs a warning if the content
// view's size is undefined.
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
scrollingContentViewManager.viewWillAppear(animated)
}
// Note: This is only required in apps that support device orientation changes.
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransition(to: size, with: coordinator)
scrollingContentViewManager.viewWillTransition(to: size, with: coordinator)
}
// Note: This is only required in apps with navigation controllers that are used to
// push sequences of view controllers with text fields that become the first
// responder in `viewWillAppear`.
override func viewSafeAreaInsetsDidChange() {
super.viewSafeAreaInsetsDidChange()
scrollingContentViewManager.viewSafeAreaInsetsDidChange()
}
}
extension SignUpViewController: SignUpControllerDelegate {
func signUpControllerScrollFirstResponderToVisible(_ signUpController: SignUpController) {
scrollingContentViewManager.scrollView.scrollFirstResponderToVisible(animated: true)
}
}