tapLocationAction in Feeds

This commit is contained in:
nixzhu
2015-11-30 13:57:30 +08:00
parent 7351ec83e3
commit 8ec0581ff2
3 changed files with 30 additions and 0 deletions
+4
View File
@@ -2673,6 +2673,10 @@ struct DiscoveredFeed: Hashable {
let latitude: CLLocationDegrees
let longitude: CLLocationDegrees
var coordinate: CLLocationCoordinate2D {
return CLLocationCoordinate2D(latitude: latitude, longitude: longitude)
}
static func fromJSONDictionary(json: JSONDictionary) -> LocationInfo? {
guard let
name = json["place"] as? String,
@@ -9,6 +9,7 @@
import UIKit
import RealmSwift
import AVFoundation
import MapKit
class FeedsViewController: BaseViewController {
@@ -899,6 +900,14 @@ extension FeedsViewController: UITableViewDataSource, UITableViewDelegate {
}
}
cell.tapLocationAction = { locationName, locationCoordinate in
let mapItem = MKMapItem(placemark: MKPlacemark(coordinate: locationCoordinate, addressDictionary: nil))
mapItem.name = locationName
mapItem.openInMapsWithLaunchOptions(nil)
}
default:
guard let cell = cell as? FeedCell else {
@@ -62,6 +62,7 @@ class FeedSocialWorkCell: FeedBasicCell {
var tapGithubRepoLinkAction: (NSURL -> Void)?
var tapDribbbleShotLinkAction: (NSURL -> Void)?
var tapDribbbleShotMediaAction: ((transitionView: UIView, image: UIImage?, imageURL: NSURL, linkURL: NSURL) -> Void)?
var tapLocationAction: ((locationName: String, locationCoordinate: CLLocationCoordinate2D) -> Void)?
var audioPlaying: Bool = false {
willSet {
@@ -134,6 +135,9 @@ class FeedSocialWorkCell: FeedBasicCell {
let tapGithubLink = UITapGestureRecognizer(target: self, action: "tapGithubLink:")
githubRepoContainerView.addGestureRecognizer(tapGithubLink)
let tapLocation = UITapGestureRecognizer(target: self, action: "tapLocation:")
locationContainerView.addGestureRecognizer(tapLocation)
}
override func setSelected(selected: Bool, animated: Bool) {
@@ -406,5 +410,18 @@ class FeedSocialWorkCell: FeedBasicCell {
}
}
}
func tapLocation(sender: UITapGestureRecognizer) {
guard let feed = feed, attachment = feed.attachment else {
return
}
if case .Location = feed.kind {
if case let .Location(locationInfo) = attachment {
tapLocationAction?(locationName: locationInfo.name, locationCoordinate: locationInfo.coordinate)
}
}
}
}