我添加了一个带有切换按钮的飞入式叠加层,就像google maps sdk示例中显示的那样。我无法找到如何向框架添加内容,需要添加标题/名称区域,然后在下面的说明框中添加。我想知道如何做到这一点,或者如果还有其他方法我应该这样做。
以下是上面的sdk示例:https://developers.google.com/maps/documentation/ios/code-samples
这是我的MapViewController.m
的代码#import "MapViewController.h"
#import <GoogleMaps/GoogleMaps.h>
static CGFloat kOverlayHeight = 180.0f;
@implementation MapViewController {
GMSMapView *mapView_;
UIView *_overlay;
__strong IBOutlet UIBarButtonItem *_flyInButton;
}
- (void)viewDidLoad {
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:39.901379 //Tony X
longitude:-105.007308 //Tony Y
zoom:18];
mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
mapView_.myLocationEnabled = YES;
mapView_.settings.myLocationButton = YES;
mapView_.padding = UIEdgeInsetsMake(0, 0, kOverlayHeight, 0);
mapView_.mapType = kGMSTypeHybrid;
self.view = mapView_;
_flyInButton = [[UIBarButtonItem alloc] initWithTitle:@"Toggle Overlay"
style:UIBarButtonItemStylePlain
target:self
action:@selector(didTapFlyIn)];
self.navigationItem.rightBarButtonItem = _flyInButton;
CGRect overlayFrame = CGRectMake(0, -kOverlayHeight, 0, kOverlayHeight);
_overlay = [[UIView alloc] initWithFrame:overlayFrame];
_overlay.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleWidth;
_overlay.backgroundColor = [UIColor colorWithHue:0.0 saturation:0.0 brightness:0.0 alpha:0.9];
[self.view addSubview:_overlay];
/*GMSMarker *markerCaleb = [[GMSMarker alloc] init];
markerCaleb.position = CLLocationCoordinate2DMake(39.900747, -105.00773400000003); //Caleb X, Caleb Y
markerCaleb.title = @"Caleb's House";
markerCaleb.snippet = @"Denver, CO";
markerCaleb.map = mapView_; */
// Creates a marker in the center of the map.
GMSMarker *markerTony = [[GMSMarker alloc] init];
markerTony.position = CLLocationCoordinate2DMake(39.901379, -105.007308); //Tony X, Tony Y
markerTony.title = @"Mr. Tony's House";
markerTony.snippet = @"Denver, CO";
markerTony.map = mapView_;
}
- (void)didTapFlyIn {
UIEdgeInsets padding = mapView_.padding;
[UIView animateWithDuration:2.0 animations:^{
CGSize size = self.view.bounds.size;
if (padding.bottom == 0.0f) {
_overlay.frame = CGRectMake(0, size.height - kOverlayHeight, size.width, kOverlayHeight);
mapView_.padding = UIEdgeInsetsMake(0, 0, kOverlayHeight, 0);
} else {
_overlay.frame = CGRectMake(0, mapView_.bounds.size.height, size.width, 0);
mapView_.padding = UIEdgeInsetsZero;
}
}];
}
@end
以下是我想要的视觉效果:https://docs.google.com/drawings/d/1ybeqXEQrmTZzFmSAOpHgVlIUbew1i55vVJIRNktGf-0/edit?usp=sharing
谢谢!