【问题标题】:iOS 6 maps- not animating PIN dropiOS 6 地图 - 没有动画 PIN 下降
【发布时间】:2012-09-15 13:00:48
【问题描述】:

我创建了一个自定义的 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;
}

【问题讨论】:

    标签: objective-c mkmapview mkannotation mkpinannotationview viewdidappear


    【解决方案1】:

    似乎在 iOS 6 中使用新的 Apple MapKit,将注释添加到 MKMapView 的顺序发生了一些变化。

    (在我自己的情况下,我曾经添加注释,然后在iOS 6之后和之前设置地图视图的委托,直到运行周期后期才出现注释,但现在他们尝试添加立即。)

    因此,可能是在连接代理之前添加注释,或者您添加注释太早而没有看到动画的问题。有关何时创建 MKMapView(假设您是在代码中而不是在 .xib 中创建)以及何时添加注释的更多代码示例可能有助于澄清问题所在。

    【讨论】:

    • 因此,通过您的实现,您也看到了与我假设相同的情况。让我在 iOS 6 中运行一些来自苹果的示例代码,看看它是如何运行的
    • 这似乎不是问题。我一直在与同样的问题作斗争,如果我不过滤用户位置,它将收到一个动画图钉;但是,没有后续引脚被动画化。此外,一个宣布的 NSLog 告诉我委托在添加注释之前被触发,这意味着它已连接。
    【解决方案2】:

    我还发现,在 iOS6 中,MKMapView 上显示的顺序/时间发生了变化。我曾经在 viewDidLoad 中将我的注释添加到地图中,这在 iOS5 中运行良好,但在 iOS6 中,引脚不会掉落,它们只是出现。我现在已将代码移至 viewDidAppear 并且图钉现在为上方的水滴设置动画。然而,它们都同时下降,而不是像在 iOS5 中那样单独下降。

    【讨论】:

      【解决方案3】:

      MkMappin 下拉弹跳动画作品 - 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;
                          }];
                      }
                  }];
              }
          }];
      }
      

      }

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-10-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-05-03
        • 2021-02-07
        • 1970-01-01
        相关资源
        最近更新 更多