diff --git a/GeofenceTester/Base.lproj/Main.storyboard b/GeofenceTester/Base.lproj/Main.storyboard index 333d007..faac25c 100644 --- a/GeofenceTester/Base.lproj/Main.storyboard +++ b/GeofenceTester/Base.lproj/Main.storyboard @@ -115,9 +115,11 @@ + + @@ -145,7 +147,16 @@ - + + + + + + + + + + diff --git a/GeofenceTester/RegionViewController.swift b/GeofenceTester/RegionViewController.swift index 13ce9b6..b63331f 100644 --- a/GeofenceTester/RegionViewController.swift +++ b/GeofenceTester/RegionViewController.swift @@ -28,7 +28,7 @@ class RegionViewController: UIViewController { }) { locationManager.stopMonitoring(for: region) } - self.dismiss(animated: true) + self.performSegue(withIdentifier: "unwindSegue", sender: self) } /* diff --git a/GeofenceTester/RegionsListViewController.swift b/GeofenceTester/RegionsListViewController.swift index 596736d..41b5db0 100644 --- a/GeofenceTester/RegionsListViewController.swift +++ b/GeofenceTester/RegionsListViewController.swift @@ -20,11 +20,7 @@ class RegionsListViewController: UIViewController, MKMapViewDelegate { super.viewDidLoad() self.title = "Monitored Regions" - self.navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .add, - target: self, - action: #selector(addRegion)) registerMapAnnotationViews() - } override func viewDidAppear(_ animated: Bool) { @@ -35,10 +31,9 @@ class RegionsListViewController: UIViewController, MKMapViewDelegate { private func registerMapAnnotationViews() { mapView.register(MKMarkerAnnotationView.self, forAnnotationViewWithReuseIdentifier: defaultReuseIdentifier) -// mapView.register(MKAnnotationView.self, forAnnotationViewWithReuseIdentifier: NSStringFromClass(SanFranciscoAnnotation.self)) } - - @objc func addRegion() { + + @IBAction func addRegion() { let alertController = UIAlertController(title: "New Region", message: "Please enter a name", preferredStyle: .alert) alertController.addTextField() alertController.addAction(UIAlertAction(title: "Cancel", @@ -93,8 +88,6 @@ class RegionsListViewController: UIViewController, MKMapViewDelegate { for region in regions { if let region = region as? CLCircularRegion { -// let overlay = MKCircle(center: region.center, radius: region.radius) -// mapView.addOverlay(overlay) let annotation = MKPointAnnotation() annotation.title = region.identifier annotation.coordinate = region.center @@ -104,16 +97,7 @@ class RegionsListViewController: UIViewController, MKMapViewDelegate { mapView.addAnnotations(mapAnnotations) mapView.showAnnotations(mapAnnotations, animated: true) } - - func coordinate(from coordinate: CLLocationCoordinate2D, latitudeDistance: CLLocationDistance, longitudeDistance: CLLocationDistance) -> CLLocationCoordinate2D { - let region = MKCoordinateRegion(center: coordinate, latitudinalMeters: latitudeDistance, longitudinalMeters: longitudeDistance) - - let newLatitude = coordinate.latitude + region.span.latitudeDelta - let newLongitude = coordinate.longitude + region.span.longitudeDelta - - return CLLocationCoordinate2D(latitude: newLatitude, longitude: newLongitude) - } - + func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? { guard !annotation.isKind(of: MKUserLocation.self) else { // Make a fast exit if the annotation is the `MKUserLocation`, as it's not an annotation view we wish to customize. @@ -122,20 +106,12 @@ class RegionsListViewController: UIViewController, MKMapViewDelegate { let annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: defaultReuseIdentifier, for: annotation) annotationView.canShowCallout = true - let rightButton = UIButton(type: .detailDisclosure) + let rightButton = UIButton(type: .infoLight) annotationView.rightCalloutAccessoryView = rightButton return annotationView } - func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer { - let renderer = MKCircleRenderer(overlay: overlay) - renderer.fillColor = UIColor.blue.withAlphaComponent(0.5) - renderer.strokeColor = UIColor.blue - renderer.lineWidth = 2 - return renderer - } - func mapView(_ mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl){ @@ -160,4 +136,9 @@ class RegionsListViewController: UIViewController, MKMapViewDelegate { detailView.locationManager = locationManager } } + + @IBAction func unwindAction(unwindSegue: UIStoryboardSegue) { + self.updateMap() + } + }