我试图在自定义markerInfoWindow中加载图片并且它不起作用 什么' s缺少所有其他工作正常,如RestName和DiscText 我尝试了3种方法 1-正常从NSRL加载图像但它崩溃了 2-与图像缓存异步加载没有任何反应 3-使用KFSwiftImageLoader lib也没什么发生
func mapView(mapView: GMSMapView!, markerInfoWindow marker: GMSMarker!) -> UIView! {
// var imageRest : UIImage!
if let infoWindow :CustomInfoRest = NSBundle.mainBundle().loadNibNamed("CustomInfo", owner: self.view, options: nil).first! as? CustomInfoRest {
rest = marker.userData as! Restaurant
infoWindow.DescText.text = rest.description
infoWindow.RestNameText.text = rest.name
RestLocation = CLLocation(latitude: rest.latitude, longitude: rest.longitude)
infoWindow.RatingView.rating = Double(rest.rate)!
infoWindow.RatingView.settings.updateOnTouch = false
infoWindow.RatingView.settings.fillMode = .Precise
let distanceBetween: CLLocationDistance =
RestLocation.distanceFromLocation(UserLocation) / 1000
let distanceInMile = distanceBetween / 1.60934
infoWindow.lan.text = String(format: "%.2f Miles", distanceInMile)
/*
let url = rest.image
let data = NSData(contentsOfURL: url!) //make sure your image in this url does exist, otherwise unwrap in a if let check
infoWindow.Restimage.image = UIImage(data: data!)
* /
// Image loading.
infoWindow.imageUrl = rest.image
// For recycled cells' late image loads.
if let image = rest.image.cachedImage {
// Cached: set immediately.
infoWindow.Restimage.image = image
infoWindow.Restimage.alpha = 1
} else {
// Not cached, so load then fade it in.
infoWindow.Restimage.alpha = 0
rest.image.fetchImage { image in
// Check the cell hasn't recycled while loading.
if infoWindow.imageUrl == self.rest.image {
infoWindow.Restimage.image = image
UIView.animateWithDuration(1) {
infoWindow.Restimage.alpha = 1
}
}
}
}
/*
infoWindow.Restimage.loadImageFromURLString(String(self.rest.image), placeholderImage: UIImage(named: "LOGO")) {
(finished, error) in
print(error)
print(finished)
}
*/
infoWindow.RestNameText.layer.cornerRadius = 10
infoWindow.layer.cornerRadius = 10
infoWindow.frame = CGRectMake(infoWindow.frame.minX,infoWindow.frame.minY-100,infoWindow.frame.width,infoWindow.frame.height)
// infoWindow.backgroundColor = UIColor.clearColor()
// infoWindow.Restimage.backgroundColor = UIColor.clearColor()
return infoWindow
} else {
return nil
}
}