Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 更新注释视图时如何在自定义注释中制作动画_Ios_Swift_Mkmapview_Mapkit_Mkannotationview - Fatal编程技术网

Ios 更新注释视图时如何在自定义注释中制作动画

Ios 更新注释视图时如何在自定义注释中制作动画,ios,swift,mkmapview,mapkit,mkannotationview,Ios,Swift,Mkmapview,Mapkit,Mkannotationview,我想做一些动画,比如“当滚动集合视图单元格时,注释针在滚动结束时向上/向下移动。但是如何做动画,比如开始滚动时注释针向上移动,在集合视图中滚动结束时注释针向下移动 //code --> For Scrolling func scrollViewDidEndDecelerating(scrollView: UIScrollView) { if scrollView == collectionView { NSLog("page collection %d",Int(s

我想做一些动画,比如“当滚动
集合视图单元格时,
注释针在滚动结束时向上/向下移动。但是如何做动画,比如开始滚动时注释针向上移动,在
集合视图中滚动结束时注释针向下移动

//code --> For Scrolling
func scrollViewDidEndDecelerating(scrollView: UIScrollView) {
    if scrollView == collectionView {
        NSLog("page collection %d",Int(scrollView.contentOffset.x/scrollView.frame.size.width))
        self.UpdateMapAnotationPin(Int(scrollView.contentOffset.x/scrollView.frame.size.width))
    }
}

//  -->When Update Pin

func UpdateMapAnotationPin(vIndex : Int) {
    if self.mapAnnotations.count != 0 {
        let info = self.mapAnnotations[vIndex]
        let aView = map.viewForAnnotation(info)
        info.imageName = "ic_map_pin1"
        info.tagPin = vIndex
        aView?.image = UIImage(named: info.imageName)

        if aView != nil {
            self.animationWithView(aView!)
        }
    }
}
//   --> For animation

func animationWithView(mkView : MKAnnotationView) {
    let point:MKMapPoint  =  MKMapPointForCoordinate(mkView.annotation!.coordinate);
    let endFrame:CGRect = mkView.frame;
    mkView.frame = CGRectMake(mkView.frame.origin.x, mkView.frame.origin.y - 20, mkView.frame.size.width, mkView.frame.size.height);
    let delay = 0.03
    UIView.animateWithDuration(0.5, delay: delay, options: UIViewAnimationOptions.CurveLinear, animations:{() in
        mkView.frame = endFrame
        }, completion:{(Bool) in
            UIView.animateWithDuration(0.05, delay: 0.0, options: UIViewAnimationOptions.CurveLinear, animations:{() in
                mkView.transform = CGAffineTransformMakeScale(1.0, 1.0) }, completion: {(Bool) in
                    UIView.animateWithDuration(0.3, delay: 0.0, options: UIViewAnimationOptions.CurveLinear, animations:{() in
                        mkView.transform = CGAffineTransformIdentity
                        }, completion: nil)
            })
    })
}

我想你想要像AirBnb应用程序注释一样设置动画。 您必须通过调用pin的viewforAnimation方法来选择pin

台阶 1.通过如下方式指定自定义id,使用进行注释

class GridAnnotation: NSObject ,MKAnnotation{
    var title: String?
    var coordinate: CLLocationCoordinate2D
    var info: String
    var index: String

    init(title: String, coordinate: CLLocationCoordinate2D, info: String,index: String) {
        self.title = title
        self.coordinate = coordinate
        self.info = info
        self.index = index
    }
} 
 override func viewDidLoad() {
        super.viewDidLoad()
 let annotationStart = GridAnnotationStart(title: "", coordinate: firstLocation.coordinate, info: "\(zoneCreateModal.id)",index: "\(0)")

                    self.mapVw.addAnnotation(annotationSta

rt)

}
2.获取所有注释

 let arrAllAnnotations = self.mapVw.annotations.filter { $0 !== self.mapVw.userLocation }


 for someAnnotation in annotationsToRemove {
                    let strId = "Your current id"
                    if someAnnotation.isKind(of: AnnotationModal.self) {
                        let annotaion = someAnnotation as! AnnotationModal
                        if annotaion.info == strId {
//Call view for animation
    self.mapVw.selectAnnotation(someAnnotation, animated: true)

             self.mapVw.view(for: someAnnotation)

                        }
                    }
                }
5.在viewForAnnotation中设置新选定注释的类型

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

        if (annotation.isKind(of: MKUserLocation.self)) {
            return nil
        }

 if annotation.isKind(of: GridAnnotationZoomModal.self) {
            let anView = MKAnnotationView(annotation: annotation, reuseIdentifier: "landingPoints")
            let annotationInfo = annotation as! GridAnnotationZoomModal
            imgView.frame = CGRect(x: 0, y: 0, width: 30, height: 30)
if anView.isSelected == true {
                imgView.image = UIImage(named: "Your selected image name")
            }else{
 imgView.image = UIImage(named: "Your image not selected name")

}           

            anView.isDraggable = false
            anView.isEnabled = true
            anView.isUserInteractionEnabled = true
            anView.tag = Int(annotationInfo.index)!
            anView.addSubview(imgView)
            anView.frame = CGRect(x: 0, y: 0, width: 30, height: 30)
            anView.centerOffset = CGPoint(x: 0,y: -15)
            return anView
        }
return nil


}

旁注,
updatemapanotionpin
缺少一个结束符
}
意味着您需要刷新地图,在滚动pin时隐藏所有pin,并在完成滚动pin显示之后。我说的对吗?不,不是说pin在任何时候都不隐藏