Как изменить высоту окна выноски аннотации Swift

Как изменить размер окна выноски аннотации на карте в Swift. Я попытался увеличить размер 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, 0, 35, 200)
    button.addTarget(self, action: "buttonClicked:", forControlEvents: UIControlEvents.TouchUpInside)


    let labelTitle :   UILabel = UILabel(frame: CGRectMake(20,0,150,50))
    labelTitle.text = selectedUstanova!.ime
    let labelSubTitle :   UILabel = UILabel(frame: CGRectMake(20,50,150,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,0,250,250));
    let leftCAV2: UIView = UIView(frame: CGRectMake(0,0,250,250));
    let imageB = UIImage(named: "bigbutton")
    let imageView : UIImageView = UIImageView(frame: CGRectMake(0,0,300,300))
    imageView.image = imageB;
    leftCAV.addSubview(imageView)
    leftCAV.addSubview(labelTitle)
    leftCAV.addSubview(labelSubTitle)
    view.leftCalloutAccessoryView = leftCAV;
    view.rightCalloutAccessoryView = leftCAV2;
}

Есть ли шанс увеличить вид? Я пытался изменить размеры левого и правого вспомогательного вида выноски, но пока безуспешно.


person Vuk Vasić    schedule 01.11.2015    source источник


Ответы (1)


Если вас интересует только изменение высоты выноски аннотации, вот простой способ. И я просто делаю высоту до 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
}
person Naveen Kumar H S    schedule 02.08.2016