-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddPhotoViewController.swift
More file actions
172 lines (107 loc) · 4.87 KB
/
Copy pathAddPhotoViewController.swift
File metadata and controls
172 lines (107 loc) · 4.87 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
//
// addPhotoViewController.swift
// IXplore
//
// Created by Alan Yu on 7/11/16.
// Copyright © 2016 Alan-Yu. All rights reserved.
//
import UIKit
import MapKit
class AddPhotoViewController: UIViewController,UIImagePickerControllerDelegate, UINavigationControllerDelegate, UIGestureRecognizerDelegate, UITextViewDelegate {
@IBOutlet weak var titleTextBox: UITextField!
@IBOutlet weak var notes: UITextView!
@IBOutlet weak var dateTextField: DateTextField!
@IBOutlet weak var latitude: UITextField!
@IBOutlet weak var longitude: UITextField!
@IBOutlet weak var imageView: UIImageView!
var currentLati:Double?
var currentLong:Double?
var delegate: AddPhotoDelegate?
let imagePicker = UIImagePickerController()
@IBAction func titleReturnPressed(sender: UITextField) {
sender.resignFirstResponder()
}
@IBAction func latDonePressed(sender: UITextField) {
sender.resignFirstResponder()
}
@IBAction func longDonePressed(sender: AnyObject) {
sender.resignFirstResponder()
}
override func viewDidLoad() {
super.viewDidLoad()
//add gesture to picture touch
let recognizer = UITapGestureRecognizer(target: self, action:#selector(imageTapped))
recognizer.delegate = self
self.imageView.addGestureRecognizer(recognizer)
//set the image picker delegate
imagePicker.delegate = self
imagePicker.sourceType = .PhotoLibrary
//set textview delegate
notes.delegate = self
//create the cancel button and put it on the navibar
let cancelButton = UIBarButtonItem(barButtonSystemItem: .Cancel, target: self, action: #selector(cancelButtonClicked))
self.navigationItem.title = "Add Entry"
self.navigationItem.leftBarButtonItem = cancelButton
// Do any additional setup after loading the view.
print("stuff is happening")
if let long:Double = currentLong {
longitude.text = String(long)
}
if let lati:Double = currentLati {
latitude.text = String(lati)
}
}
func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWithGestureRecognizer otherGestureRecognizer: UIGestureRecognizer) -> Bool {
return true
}
func imageTapped(){
self.presentViewController(imagePicker, animated: true, completion: nil)
}
func imagePickerControllerDidCancel(picker: UIImagePickerController) {
picker.dismissViewControllerAnimated(true, completion: nil)
}
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
self.imageView.image = info[UIImagePickerControllerOriginalImage] as? UIImage
picker.dismissViewControllerAnimated(true, completion: nil)
}
func textViewDidBeginEditing(textView: UITextView) {
if(textView.text == "notes"){
textView.text = ""
textView.textColor = UIColor.blackColor()
}
}
func textViewDidEndEditing(textView: UITextView) {
if(textView.text == ""){
textView.text = "notes"
textView.textColor = UIColor.lightGrayColor()
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func cancelButtonClicked() {
//tells the parent view controller to dismiss the current view controller
self.navigationController?.popViewControllerAnimated(true)
}
@IBAction func saveButton(sender: AnyObject) {
let title = titleTextBox.text
//if no notes exist, just default to nothing
let note = notes.text
let date = dateTextField.datePicker.date
let long:Double? = Double(longitude.text!)
let lati:Double? = Double(latitude.text!)
let pictureImage = imageView.image
let newEntry = Entry(titleString: title!, locationCoord: CLLocationCoordinate2D(latitude: lati!, longitude: long!), pictureDate: date, pictureNotes: note, picture: pictureImage!)
delegate?.addEntry(newEntry)
self.navigationController?.popViewControllerAnimated(true)
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}