Ios 使用Swift 2.0最佳方法的自定义详图索引视图?
我想从Ios 使用Swift 2.0最佳方法的自定义详图索引视图?,ios,swift,uiview,mkmapview,mkannotationview,Ios,Swift,Uiview,Mkmapview,Mkannotationview,我想从xib创建自定义callout视图。我创建了一个xib和自定义的注释视图类。我想使用我的MapViewControllersegue,它的名称是showdeailsegue,因为这个segue是一个Pushsegue。当用户点击我的Callout视图中的按钮时,它应该执行我的showDetailsegue 我搜索了所有的文档、教程、指南和问题,但我可以 无法使用Swift找到任何解决方案。也没有自定义库。我找不到任何解决方案,因为已经三天了 我的CalloutView.xibfileVie
xib
创建自定义callout视图。我创建了一个xib和自定义的注释视图
类。我想使用我的MapViewController
segue,它的名称是showdeail
segue,因为这个segue是一个Pushsegue。当用户点击我的Callout视图中的按钮时,它应该执行我的showDetail
segue
我搜索了所有的文档、教程、指南和问题,但我可以
无法使用Swift找到任何解决方案。也没有自定义库。我找不到任何解决方案,因为已经三天了
我的CalloutView.xib
fileView
是我的CustomAnnotationView,它的名称是CalloutAnnotationView.swift
和文件的所有者是MapViewController
它允许我使用MapViewController
序列
这是我的CalloutAnnotationView.swift
override func hitTest(point: CGPoint, withEvent event: UIEvent?) -> UIView? {
let hitView = super.hitTest(point, withEvent: event)
if (hitView != nil) {
self.superview?.bringSubviewToFront(self)
}
return hitView
}
override func pointInside(point: CGPoint, withEvent event: UIEvent?) -> Bool {
let rect = self.bounds
var isInside = CGRectContainsPoint(rect, point)
if (!isInside) {
for view in self.subviews {
isInside = CGRectContainsPoint(view.frame, point)
if (isInside) {
}
}
}
return isInside
}
override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
let calloutViewController = MapViewController(nibName: "CalloutView", bundle: nil)
if selected {
calloutViewController.view.clipsToBounds = true
calloutViewController.view.layer.cornerRadius = 10
calloutViewController.view.center = CGPointMake(self.bounds.size.width * 0.5, -calloutViewController.view.bounds.size.height * 0.5)
self.addSubview(calloutViewController.view)
} else {
// Dismiss View
calloutViewController.view.removeFromSuperview()
}
}
MyMapViewController.swift
codes
// MARK: - MapKit Delegate Methods
func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {
if let annotation = annotation as? Veterinary { // Checking annotations is not User Location.
var pinView = mapView.dequeueReusableAnnotationViewWithIdentifier(Constants.MapViewAnnotationViewReuseIdentifier) as? CalloutAnnotationView
if pinView == nil { // If it is nil it created new Pin View
pinView = CalloutAnnotationView(annotation: annotation, reuseIdentifier: Constants.MapViewAnnotationViewReuseIdentifier)
pinView?.canShowCallout = false
} else { pinView?.annotation = annotation } // If it is NOT nil it uses old annotations.
// Checking pin colors from Veterinary Class PinColor Method
pinView?.image = annotation.pinColors()
//pinView?.rightCalloutAccessoryView = UIButton(type: .DetailDisclosure)
return pinView
}
return nil
}
这些代码可以很好地加载我的xib文件。我从一个按钮创建了iAction
,它使用showdail
segue执行从MapViewController
到我的DetailViewController
的分段但问题是它不会从superview
中删除我的自定义调用视图,所以我不能取消调用视图
如何解决此问题,或者使用myMapViewController
推送序列创建自定义calloutView
的最佳方法是什么
非常感谢。在您的MKMapView代理中,查看在切换时是否调用此命令:
func mapView(mapView: MKMapView, didDeselectAnnotationView view: MKAnnotationView) {
if let annotation = view.annotation as? Veterinary {
mapView.removeAnnotation(annotation)
}
}
我希望这能帮助你解决这个问题
func mapView(mapView: MKMapView, didDeselectAnnotationView view: MKAnnotationView) {
if view.isKindOfClass(AnnotationView)
{
for subview in view.subviews
{
subview.removeFromSuperview()
}
}
}