View difference between Paste ID: fxPBbQ1y and h9zM88BN
SHOW: | | - or go back to the newest paste.
1
//
2
//  SignUpViewController.swift
3
//  Culpability
4
//
5
//  Created by Lazar Nikolov on 2/26/16.
6
//  Copyright © 2016 Lazar Nikolov. All rights reserved.
7
//
8
9
import UIKit
10
11
class SignUpViewController: UIViewController {
12
13
    @IBOutlet weak var tfUsername: UITextField!
14
    @IBOutlet weak var tfPassword: UITextField!
15
    @IBOutlet weak var tfConfirmPassword: UITextField!
16
    
17
    override func viewDidLoad() {
18
        super.viewDidLoad()
19
        
20
        NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWillShow:"), name: UIKeyboardWillShowNotification, object: nil)
21
        NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWillHide:"), name: UIKeyboardWillHideNotification, object: nil)
22
23
    }
24
    
25-
    func textFieldShouldReturn(textField: UITextField) -> Bool {
25+
26-
        if textField == tfUsername {
26+
27-
            tfPassword.becomeFirstResponder()
27+
28-
        } else if textField == tfPassword {
28+
29-
            tfConfirmPassword.becomeFirstResponder()
29+
30-
        } else if textField == tfConfirmPassword {
30+
31-
            self.view.endEditing(true)
31+
32
                    let verticalDifference = usernameBottomY - (self.view.frame.height - keyboardSize.height)
33-
        return true
33+
34
                        self.view.frame.origin.y -= verticalDifference
35
                    })
36
                }
37
            } else if self.tfPassword.isFirstResponder() {
38
                let passwordBottomY = self.tfPassword.frame.origin.y + self.tfPassword.frame.height
39
                
40
                if passwordBottomY <= self.view.frame.height && passwordBottomY >= (self.view.frame.height - keyboardSize.height) {
41
                    // Scroll it
42
                    let verticalDifference = passwordBottomY - (self.view.frame.height - keyboardSize.height)
43
                    UIView.animateWithDuration(0.3, animations: {
44
                        self.view.frame.origin.y -= verticalDifference
45
                    })
46
                }
47
            } else if self.tfConfirmPassword.isFirstResponder() {
48
                let confirmPasswordBottomY = self.tfConfirmPassword.frame.origin.y + self.tfConfirmPassword.frame.height
49
                
50
                if confirmPasswordBottomY <= self.view.frame.height && confirmPasswordBottomY >= (self.view.frame.height - keyboardSize.height) {
51
                    // Scroll it
52
                    let verticalDifference = confirmPasswordBottomY - (self.view.frame.height - keyboardSize.height)
53
                    UIView.animateWithDuration(0.3, animations: {
54
                        self.view.frame.origin.y -= verticalDifference
55
                    })
56
                }
57
            }
58
        }
59
    }
60
    
61
    func keyboardWillHide(notification: NSNotification) {
62
        if self.view.frame.origin.y < 0 {
63
            UIView.animateWithDuration(0.3, animations: {
64
                self.view.frame.origin.y = 0
65
            })
66
        }
67
    }
68
}