我正在将自定义视图加载从xib转换为UIImage
以显示为标记icon.it已完成,但问题是当在for循环中执行此操作时显示100个标记UI卡住是因为加载xib自定义视图?
下面是调用for循环的函数
func generateSpot(Prop: Property) -> Spot {
let latStr = Prop.propLat
let langStr = Prop.propLang as NSString
let langDbl : Double = Double(langStr.floatValue)
let latDbl : Double = Double(latStr.floatValue)
let marker:GMSMarker = GMSMarker()
marker.position = CLLocationCoordinate2DMake(langDbl,latDbl)
marker.appearAnimation = kGMSMarkerAnimationPop
marker.title = Prop.propBuildingName as String
marker.snippet = Prop.propCode as String
marker.infoWindowAnchor = CGPointMake(0.44, 0.45)
let sizeVar:CGSize = CGSize(width: 41, height: 37)
let customeMarker :CustomMarker = NSBundle.mainBundle().loadNibNamed("CustomView", owner: self.view, options: nil).first! as! CustomMarker
customeMarker.frame = CGRectMake(customeMarker.frame.minX,customeMarker.frame.minY,customeMarker.frame.width,customeMarker.frame.height)
customeMarker.mappedNumbers.layer.masksToBounds = true
customeMarker.mappedNumbers.layer.cornerRadius = 8
customeMarker.mappedNumbers.text = Prop.propSequence as String
if Prop.propStatus == self.constants!.status.STATUS_COMPLETED_XML
{
customeMarker.mappedNumbers.backgroundColor = self.utility!.uicolorFromHex(0x70b420)
customeMarker.arrowImage.tintColor = self.utility!.uicolorFromHex(0x70b420)
}
if Prop.propStatus == self.constants!.status.STATUS_DRAFT_XML
{
customeMarker.mappedNumbers.backgroundColor = self.utility!.uicolorFromHex(0xd2cb46)
customeMarker.arrowImage.tintColor = self.utility!.uicolorFromHex(0x70b420)
}
if Prop.propStatus == self.constants!.status.STATUS_PENDING_XML
{
customeMarker.mappedNumbers.backgroundColor = self.utility!.uicolorFromHex(0xd44646)
customeMarker.arrowImage.tintColor = self.utility!.uicolorFromHex(0xd44646)
}
UIGraphicsBeginImageContextWithOptions(sizeVar, false, 0)
customeMarker.drawViewHierarchyInRect(customeMarker.bounds, afterScreenUpdates: true)
let newImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
marker.icon = newImage
marker.map = self.googleMapView
let spotObje:Spot = Spot()
spotObje.location = marker.position
spotObje.marker = marker
return spotObje
}
答案 0 :(得分:0)
解决 取代
customeMarker.drawViewHierarchyInRect(customeMarker.bounds, afterScreenUpdates: true)
带
customeMarker.layer.renderInContext(UIGraphicsGetCurrentContext()!)
参考:drawViewHierarchyInRect:afterScreenUpdates: delays other animations