ios – 如何更改注释标注窗口Swift的高度

前端之家收集整理的这篇文章主要介绍了ios – 如何更改注释标注窗口Swift的高度前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如何在 Swift中更改Map上的注释标注窗口的大小.我尝试在右视图和左视图的每个组件上创建一个更大的CGSize但没有任何成功最终视图的高度仍然是相同的.

这是我的代码

func mapView(mapView: MKMapView,viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {

    print("delegate called")

    if !(annotation is CustomPointAnnotation) {
        return nil
    }

    let reuseId = "test"

    var anView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId)
    if anView == nil {
        anView = MKAnnotationView(annotation: annotation,reuseIdentifier: reuseId)


         selectedUstanova = (annotation as! CustomPointAnnotation).ustanova


        anView!.canShowCallout = true
    }
    else {
        anView!.annotation = annotation
    }

    //Set annotation-specific properties **AFTER**
    //the view is dequeued or created...

    let cpa = annotation as! CustomPointAnnotation
    anView!.image = UIImage(named:cpa.imageName)
    return anView
}
func mapView(mapView: MKMapView,didSelectAnnotationView view: MKAnnotationView)
{
    let button : UIButton = UIButton(type: UIButtonType.Custom) as UIButton
    let image = UIImage(named: "telephone")
    button.layer.cornerRadius = 10
    button.layer.backgroundColor = UIColor.whiteColor().CGColor
    button.layer.masksToBounds = true
    button.setBackgroundImage(image,forState: UIControlState.Normal)
    button.frame = CGRectMake(0,35,200)
    button.addTarget(self,action: "buttonClicked:",forControlEvents: UIControlEvents.TouchUpInside)


    let labelTitle :   UILabel = UILabel(frame: CGRectMake(20,150,50))
    labelTitle.text = selectedUstanova!.ime
    let labelSubTitle :   UILabel = UILabel(frame: CGRectMake(20,50,100))
    var ustanovaOpis = ""
    if selectedUstanova!.opis != nil{
        ustanovaOpis+=selectedUstanova!.opis!+"\n"
    }
    if selectedUstanova!.telefon != nil{
        ustanovaOpis+=selectedUstanova!.telefon!
    }
    labelSubTitle.text = ustanovaOpis
    let leftCAV : UIView = UIView(frame: CGRectMake(0,250,250));
    let leftCAV2: UIView = UIView(frame: CGRectMake(0,250));
    let imageB = UIImage(named: "bigbutton")
    let imageView : UIImageView = UIImageView(frame: CGRectMake(0,300,300))
    imageView.image = imageB;
    leftCAV.addSubview(imageView)
    leftCAV.addSubview(labelTitle)
    leftCAV.addSubview(labelSubTitle)
    view.leftCalloutAccessoryView = leftCAV;
    view.rightCalloutAccessoryView = leftCAV2;
}

是否有机会使View更大我尝试改变左右标注配件视图的尺寸但到目前为止没有成功.

解决方法

如果您只对更改注释标注的高度感兴趣,这是一种简单的方法.我只是将高度提高到200个单位.

func mapView(mapView: MKMapView,viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {
    if annotation is MKUserLocation {
        return nil
    }
    let reuseID = "pin"
    var pinView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseID) as? MKPinAnnotationView
    if pinView == nil {
        pinView = MKPinAnnotationView(annotation: annotation,reuseIdentifier: reuseID)
        pinView!.canShowCallout = true
        pinView!.animatesDrop = true
        pinView!.pinTintColor = UIColor.blackColor()
    }
     pinView!.detailCalloutAccessoryView = self.configureDetailView(pinView!)
    return pinView
}

func configureDetailView(annotationView: MKAnnotationView) -> UIView {
    let snapshotView = UIView()
    let views = ["snapshotView": snapshotView]
    snapshotView.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:[snapshotView(200)]",options: [],metrics: nil,views: views))
    //do your work 
    return snapshotView
}

猜你在找的iOS相关文章