按纬度订购 MKAnnotationViews 数组?
Order array of MKAnnotationViews by latitude?
基于一些动态标准,我在mapkit中标注了各种坐标,并将它们动画化如下:
-(void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)annotationViews {
float delay = 0;
for (MKAnnotationView *annView in annotationViews) {
annView.transform = CGAffineTransformMakeScale(0.01, 0.01);
CLLocationCoordinate2D x = annView.annotation.coordinate;
float y = x.latitude;
[UIView animateWithDuration:.2
delay:delay
usingSpringWithDamping:damp
initialSpringVelocity:vel
options:0
animations:^{
annView.transform = CGAffineTransformIdentity;
} completion:^(BOOL finished) {
}];
delay += .02;
}
}
我想做的是在对 annotationView 进行动画处理之前对其进行排序。具体来说,我想访问每个 annotationView 的坐标:
CLLocationCoordinate2D x = annView.annotation.coordinate;
并按纬度排序。最终效果应该是它们从西向东呈波纹状动画。
可以按纬度排序吗?
首先创建一个新的排序视图数组,然后遍历排序数组。
但是如果你想"animate in a ripple from west to east"那么注释应该按经度排序(而不是纬度)。
示例:
-(void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)annotationViews {
NSArray *sortedViews = [annotationViews sortedArrayUsingComparator:
^NSComparisonResult(MKAnnotationView *obj1, MKAnnotationView *obj2) {
if (obj1.annotation.coordinate.longitude < obj2.annotation.coordinate.longitude)
return NSOrderedAscending;
else
if (obj1.annotation.coordinate.longitude > obj2.annotation.coordinate.longitude)
return NSOrderedDescending;
else
return NSOrderedSame;
}];
float delay = 0;
for (MKAnnotationView *annView in sortedViews) {
annView.transform = CGAffineTransformMakeScale(0.01, 0.01);
[UIView animateWithDuration:.2
delay:delay
usingSpringWithDamping:damp
initialSpringVelocity:vel
options:0
animations:^{
annView.transform = CGAffineTransformIdentity;
} completion:^(BOOL finished) {
}];
delay += .02;
}
}
基于一些动态标准,我在mapkit中标注了各种坐标,并将它们动画化如下:
-(void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)annotationViews {
float delay = 0;
for (MKAnnotationView *annView in annotationViews) {
annView.transform = CGAffineTransformMakeScale(0.01, 0.01);
CLLocationCoordinate2D x = annView.annotation.coordinate;
float y = x.latitude;
[UIView animateWithDuration:.2
delay:delay
usingSpringWithDamping:damp
initialSpringVelocity:vel
options:0
animations:^{
annView.transform = CGAffineTransformIdentity;
} completion:^(BOOL finished) {
}];
delay += .02;
}
}
我想做的是在对 annotationView 进行动画处理之前对其进行排序。具体来说,我想访问每个 annotationView 的坐标:
CLLocationCoordinate2D x = annView.annotation.coordinate;
并按纬度排序。最终效果应该是它们从西向东呈波纹状动画。
可以按纬度排序吗?
首先创建一个新的排序视图数组,然后遍历排序数组。
但是如果你想"animate in a ripple from west to east"那么注释应该按经度排序(而不是纬度)。
示例:
-(void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)annotationViews {
NSArray *sortedViews = [annotationViews sortedArrayUsingComparator:
^NSComparisonResult(MKAnnotationView *obj1, MKAnnotationView *obj2) {
if (obj1.annotation.coordinate.longitude < obj2.annotation.coordinate.longitude)
return NSOrderedAscending;
else
if (obj1.annotation.coordinate.longitude > obj2.annotation.coordinate.longitude)
return NSOrderedDescending;
else
return NSOrderedSame;
}];
float delay = 0;
for (MKAnnotationView *annView in sortedViews) {
annView.transform = CGAffineTransformMakeScale(0.01, 0.01);
[UIView animateWithDuration:.2
delay:delay
usingSpringWithDamping:damp
initialSpringVelocity:vel
options:0
animations:^{
annView.transform = CGAffineTransformIdentity;
} completion:^(BOOL finished) {
}];
delay += .02;
}
}