Objective c iOS 6贴图-不设置针掉落动画
我创建了一个自定义的MKAnnotation类,它一直在工作,直到iOS 6问世。从那时起,我的引脚被添加到苹果地图,但现在没有下降动画!是这样设置的还是我做事的方式有问题。我已经设置了1秒的延迟,直到调用将注释添加到地图的方法为止,这样我就可以看到在视图出现之前是否真的发生了放置动画-尽管如此,插针还是不知从何处出现而没有放置。以下是我使用的代码:Objective c iOS 6贴图-不设置针掉落动画,objective-c,mkmapview,mkannotation,mkpinannotationview,viewdidappear,Objective C,Mkmapview,Mkannotation,Mkpinannotationview,Viewdidappear,我创建了一个自定义的MKAnnotation类,它一直在工作,直到iOS 6问世。从那时起,我的引脚被添加到苹果地图,但现在没有下降动画!是这样设置的还是我做事的方式有问题。我已经设置了1秒的延迟,直到调用将注释添加到地图的方法为止,这样我就可以看到在视图出现之前是否真的发生了放置动画-尽管如此,插针还是不知从何处出现而没有放置。以下是我使用的代码: -(MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(Ann
-(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;
}
随着iOS 6中新的Apple MapKit的出现,在MKMapView中添加注释的顺序似乎发生了一些变化 (在我自己的例子中,我曾经添加注释,然后立即设置地图视图的委托,在iOS 6之前,注释直到运行周期的后期才出现,但现在它们尝试立即添加。)
因此,可能存在这样的问题:要么在连接代理之前添加注释,要么添加注释太早,只是看不到动画。更多关于何时创建MKMapView的代码示例(假设您是在代码中而不是在.xib中创建的)以及何时添加注释可能有助于澄清错误。我还发现,在iOS6中,MKMapView上显示的顺序/时间发生了变化。我曾经在viewDidLoad中将注释添加到地图中,这在iOS5中运行良好,但在iOS6中,管脚不会掉落,它们只是出现。现在,我已经将代码移动到ViewDidDisplay,并且图钉现在可以从上面设置跌落动画。然而,它们一次全部掉落,不像在iOS 5中那样单独掉落。MkMappin下拉弹跳动画作品-Prem Kumar(iOS开发者)
}因此,在您的实现中,您也看到了与我假设的相同的情况。让我在iOS 6中运行一些来自苹果的示例代码,看看如何运行这似乎不是问题所在。我一直在与这个问题作斗争,如果我不过滤用户位置,它将收到一个动画pin;但是,不会为后续管脚设置动画。另外,一个声明NSLog告诉我,在添加注释之前,委托被触发,这意味着它已连接。
-(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;
}];
}
}];
}
}];
}