iOS   发布时间:2022-03-30  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了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 – 如何更改注释标注窗口Swift的高度全部内容,希望文章能够帮你解决ios – 如何更改注释标注窗口Swift的高度所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。