在iOS上动画MarkerinfoWindow

时间:2013-10-30 10:36:57

标签: ios google-maps google-maps-sdk-ios

当我使用iOS SDK的谷歌地图时,我可以通过委派来改变MarkerInfoWindow的视图

- (UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)marker

我的问题是,当它即将显示时,我可以设置信息窗口(而不是引脚a.k.a标记)的弹出效果吗?我在这方面没有任何线索...我认为这是可能的,但是有人可以在这里给我提供任何建议吗?

这是我的源样本

@interface BasicMapViewController()

@property (nonatomic, strong) GMSMapView* mapView;

@end

@implementation BasicMapViewController

@synthesize mapView;


- (void)viewDidLoad {
  [super viewDidLoad];
  GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.868
                                                          longitude:151.2086
                                                               zoom:9];
    CGRect mapRect= CGRectMake(0, 0, 320, 320);
    mapView= [GMSMapView mapWithFrame:mapRect camera:camera];
    mapView.delegate= self;
    [self.view addSubview:mapView];

    UIButton* button= [UIButton buttonWithType:UIButtonTypeRoundedRect];
    button.frame= CGRectMake(120, 350, 100, 50);
    [button addTarget:self
               action:@selector(buttonClicked)
     forControlEvents:UIControlEventTouchDown];
    [button setTitle:@"Add Pins" forState:UIControlStateNormal];

    [self.view addSubview:button];
}

#pragma mark - button handler

-(void)buttonClicked
{
    NSLog(@"clicked");

    // Add a custom 'glow' marker around Sydney.
    GMSMarker *sydneyMarker = [[GMSMarker alloc] init];
    sydneyMarker.icon = [UIImage imageNamed:@"glow-marker"];
    sydneyMarker.position = CLLocationCoordinate2DMake(-33.8683, 151.2086);
    sydneyMarker.appearAnimation= kGMSMarkerAnimationPop;
    sydneyMarker.map = mapView;

    GMSMarker *mbourneMarker = [[GMSMarker alloc] init];
    mbourneMarker.icon = [UIImage imageNamed:@"glow-marker"];
    mbourneMarker.position = CLLocationCoordinate2DMake(-37.814107, 144.963280);
    mbourneMarker.appearAnimation= kGMSMarkerAnimationPop;
    mbourneMarker.map = mapView;
}


#pragma mark - GMSMapView delegate methods

- (UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)marker {

        CustomInfoWindow* view =  [[[NSBundle mainBundle] loadNibNamed:@"InfoWindowView" owner:self options:nil] objectAtIndex:0];
        view.title.text= @"Sydney";
        view.subtitle.text= @"Opera House";

    return view;
}

-(void)mapView:(GMSMapView *)mapView didTapInfoWindowOfMarker:(GMSMarker *)marker
{
    NSLog(@"info window tapped!");
}


@end

1 个答案:

答案 0 :(得分:1)

不幸的是,在当前版本(1.7)中似乎是不可能的。

看起来地图上显示的视图是" copy"您在mapView:markerInfoWindow:中返回的内容。您发送到此视图的任何消息只有在您点击标记时才会生效。虽然并非所有发送到此视图的消息都可以传送到最终视图(我们看到的那个)。例如。您可以更改其框架大小,但不能更改原点(位置可以通过标记infoWindowAnchor属性设置),您可以更改图层,添加子视图,但无法处理其子视图的触摸(至少我无法破解它... ..

希望这些信息有所帮助,并且真的希望它们在未来的版本中能够提供更大的灵活性。