我创建了一个自定义的MKAnnotation类,它一直在运行 - 直到iOS 6出现。从那时起,我的针脚被添加到苹果地图中,但现在没有掉落动画!它是如何设置的,或者我正在做的事情可能存在问题。我设置了1秒的延迟,直到调用添加注释到地图的方法为止,因此我可以看到在视图出现之前是否实际发生了放置动画 - 但是,引脚只是突然出现而没有丢失。这是我正在使用的代码:
-(MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(Annotation*)annotation
{
NSLog(@"the annotation ID is: %@", annotation.ID);
MKPinAnnotationView *MyPin=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"current"];
UIButton *goToObjectButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[goToObjectButton addTarget:self action:@selector(goToObjectClick:) forControlEvents:UIControlEventTouchUpInside];
MyPin.pinColor = MKPinAnnotationColorRed;
MyPin.rightCalloutAccessoryView = goToObjectButton;
MyPin.draggable = NO;
MyPin.highlighted = YES;
MyPin.animatesDrop=YES;
MyPin.canShowCallout = YES;
return MyPin;
}
答案 0 :(得分:3)
我还发现在iOS6中,MKMapView上显示的内容的顺序/时间已经改变。我曾经在viewDidLoad中将我的注释添加到地图中,这在iOS5中运行良好,但是对于iOS6,引脚不会掉落它们只是出现。我现在已经将代码移动到viewDidAppear,并且引脚现在为上面的下降设置动画。然而,它们都会立即下降,而不是像在iOS5中那样单独下降。
答案 1 :(得分:3)
MkMappin Dropdown Bounce Animation Works - Prem Kumar(iOS开发人员)
-(void)addPinWithTitle:(NSString *)title AndCoordinate:(NSString *)strCoordinate
{
MKPointAnnotation *mapPin = [[MKPointAnnotation alloc] init];
// clear out any white space
strCoordinate = [strCoordinate stringByReplacingOccurrencesOfString:@" " withString:@""];
// convert string into actual latitude and longitude values
NSArray *components = [strCoordinate componentsSeparatedByString:@","];
double latitude = [components[0] doubleValue];
double longitude = [components[1] doubleValue];
// setup the map pin with all data and add to map view
CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(latitude, longitude);
mapPin.title = [title valueForKey:@"restaurantBranchName"];
mapPin.coordinate = coordinate;
[locationMapView addAnnotation:mapPin];
}
- (MKAnnotationView *)mapView:(MKMapView *)mapview viewForAnnotation:(id <MKAnnotation>)annotation
{
if ([annotation isKindOfClass:[MKUserLocation class]])
return nil;
static NSString* AnnotationIdentifier = @"AnnotationIdentifier";
MKAnnotationView *annotationView = [locationMapView dequeueReusableAnnotationViewWithIdentifier:AnnotationIdentifier];
if(annotationView)
return annotationView;
else
{
MKAnnotationView *annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation
reuseIdentifier:AnnotationIdentifier];
annotationView.canShowCallout = YES;
UIImage *img = [UIImage imageNamed:@"orange_restaurant"];
UIImageView *imageView = [[UIImageView alloc] initWithImage:img];
imageView.frame=CGRectMake(0, 0, 40, 40);
imageView.contentMode=UIViewContentModeScaleAspectFit;
imageView.center = annotationView.center;
[annotationView addSubview:imageView];
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton setTitle:annotation.title forState:UIControlStateNormal];
annotationView.rightCalloutAccessoryView = rightButton;
UIView *rightView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 30, 30)];
rightView.backgroundColor=ThemeColor;
rightView.layer.cornerRadius=rightView.frame.size.width/2;
annotationView.leftCalloutAccessoryView=rightView;
annotationView.canShowCallout = YES;
annotationView.draggable = YES;
return annotationView;
}
return nil;
}
- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views {
MKAnnotationView *aV;
for (aV in views) {
// Don't pin drop if annotation is user location
if ([aV.annotation isKindOfClass:[MKUserLocation class]]) {
continue;
}
// Check if current annotation is inside visible map rect, else go to next one
MKMapPoint point = MKMapPointForCoordinate(aV.annotation.coordinate);
if (!MKMapRectContainsPoint(mapView.visibleMapRect, point)) {
continue;
}
CGRect endFrame = aV.frame;
aV.frame = CGRectMake(aV.frame.origin.x, aV.frame.origin.y - self.view.frame.size.height, aV.frame.size.width, aV.frame.size.height);
[UIView animateWithDuration:0.5 delay:0.04*[views indexOfObject:aV] options: UIViewAnimationOptionCurveLinear animations:^{
aV.frame = endFrame;
}completion:^(BOOL finished){
if (finished) {
[UIView animateWithDuration:0.5 animations:^{
aV.frame = CGRectMake(aV.frame.origin.x, aV.frame.origin.y - self.view.frame.size.height/6, aV.frame.size.width, aV.frame.size.height);
}completion:^(BOOL finished){
if (finished) {
[UIView animateWithDuration:0.5 animations:^{
aV.frame = endFrame;
}];
}
}];
}
}];
}
}
答案 2 :(得分:1)
似乎在iOS 6中使用新的Apple MapKit时,注释添加到MKMapView上的顺序发生了一些变化。
(在我自己的情况下,我曾经添加注释,然后立即设置地图视图的委托,在iOS 6之前,注释直到运行周期的后期才出现,但现在他们尝试添加立即。)
因此,在委托被连接之前添加注释或者过早添加注释而只是看不到动画可能是一个问题。有关何时创建MKMapView的更多代码示例(假设您在代码中而不是在.xib中执行)以及添加注释时可能有助于澄清错误。