Skip to content

Instantly share code, notes, and snippets.

@lfarah
Created August 18, 2016 23:57
Show Gist options
  • Save lfarah/d047ac2876c3733c69675a9915f4557d to your computer and use it in GitHub Desktop.
Save lfarah/d047ac2876c3733c69675a9915f4557d to your computer and use it in GitHub Desktop.
//
// BubblePreviewViewController.swift
// Bable
//
// Created by Lucas Farah on 8/15/16.
// Copyright © 2016 labx. All rights reserved.
//
import UIKit
import MapKit
import Alamofire
class BubblePreviewViewController: UIViewController {
@IBOutlet weak var map: MKMapView!
@IBOutlet weak var imgvBubble: UIImageView!
@IBOutlet weak var txtDescription: UITextView!
@IBOutlet weak var imgvBackgroundBubble: UIImageView!
@IBOutlet weak var lblTitleBubble: UILabel!
var event: Event?
var images = ["", "xaxas", "xoxos.jpg", "xixis"]
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
self.map.delegate = self
// Set map view delegate with controller
// Drop a pin
if let ev = event {
let dropPin = MyAnnotation(location: ev.location)
dropPin.title = ev.title
map.addAnnotation(dropPin)
map.showAnnotations([dropPin], animated: true)
self.txtDescription.text = ev.description
self.lblTitleBubble.text = ev.title
self.imgvBubble.image = ev.image
self.imgvBubble.roundView()
self.imgvBubble.clipsToBounds = true
imgvBackgroundBubble.image = ev.image
imgvBackgroundBubble.contentMode = .ScaleAspectFit
imgvBackgroundBubble.blurImage()
}
}
@IBAction func butContinue(sender: AnyObject) {
/*
Title
Description
Image
Latitude
Longitude
*/
let parameters: [String: AnyObject] = ["title": self.lblTitleBubble.text!, "description": self.txtDescription.text!, "image_url": "http://static1.squarespace.com/static/56744689c647ad29367d624e/t/5697f71405caa7eb5b85475c/1450734853177/The+Maxim+Party+2016+Pavilion.jpg?format=2500w", "latitude": (event?.location.latitude)!, "longitude": (event?.location.longitude)!]
Alamofire.request(.POST, "http://ec2-52-91-210-138.compute-1.amazonaws.com/event/2342432", parameters: parameters)
.responseJSON { response in
// Parsing JSON
if let JSON = response.result.value {
print(JSON)
} else {
print(response)
}
self.txtDescription.text = self.event!.description
self.lblTitleBubble.text = self.event!.title
self.imgvBubble.image = self.event!.image
self.imgvBubble.roundView()
self.imgvBubble.clipsToBounds = true
self.imgvBackgroundBubble.image = self.event!.image
self.imgvBackgroundBubble.contentMode = .ScaleAspectFit
self.imgvBackgroundBubble.blurImage()
}
self.navigationController?.popToRootViewControllerAnimated(true)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
extension BubblePreviewViewController: MKMapViewDelegate {
func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {
if (annotation is MKUserLocation) {
// if annotation is not an MKPointAnnotation (eg. MKUserLocation),
// return nil so map draws default view for it (eg. blue dot)...
return nil
}
if let not = annotation as? MyAnnotation {
let reuseId = "test"
var anView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId)
if anView == nil {
anView = MKAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
let image = event?.image
anView!.image = UIImage.scaleTo(image: image!, w: 40, h: 40).circle
anView!.canShowCallout = true
}
else {
// we are re-using a view, update its annotation reference...
anView!.annotation = annotation
}
return anView
}
return nil
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment