0

GMSMapView を使用する iPhone アプリケーションを作成しており、マップの上にツールバーを追加できるようにしたいと考えています。これは私のコードです:

#import "MapViewController.h"
#import <GoogleMaps/GoogleMaps.h>

@interface MapViewController ()

@end

@implementation MapViewController
{
GMSMapView *mapView_;
id<GMSMarker> myMarker;
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
    // Custom initialization
}
return self;
}

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

- (IBAction)back:(id)sender
{
[self dismissViewControllerAnimated:YES completion:NULL];
}

// You don't need to modify the default initWithNibName:bundle: method.

- (void)loadView
{
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:30.616083 longitude:-96.338908 zoom:13];

mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
mapView_.myLocationEnabled = YES;
mapView_.delegate = self;
self.view = mapView_;

GMSMarkerOptions *options = [[GMSMarkerOptions alloc] init];
options.position = CLLocationCoordinate2DMake(30.616083, -96.338908);
options.title = @"College Station";
options.snippet = @"Texas";
[mapView_ addMarkerWithOptions:options];
}

#pragma mark - GMSMapViewDelegate
- (void)mapView:(GMSMapView *)mapView
didTapAtCoordinate:(CLLocationCoordinate2D)coordinate
{
[myMarker remove];

NSLog(@"You tapped at %f,%f", coordinate.latitude, coordinate.longitude);
GMSMarkerOptions *marker = [[GMSMarkerOptions alloc] init];
marker.position = CLLocationCoordinate2DMake(coordinate.latitude, coordinate.longitude);
marker.title = @"Tap Event";
// (icon for marker) marker.icon = [UIImage imageNamed:@"house"];
myMarker = [mapView_ addMarkerWithOptions:marker];
}

@end

私のストーリーボードにはツールバーがありますが、それを GMSMapView の上に表示する方法がわかりません。私はiOSが初めてで、オンラインでソリューションを検索しましたが、GMSMapViewではうまくいきませんでした。

4

1 に答える 1

0

ビューを mapView_ に設定したため、StoryBoard で作成されたビューはオーバーライドされます。次のコードを使用して、セグメント化されたコントロールとボタンを含むツールバーを追加しました。

CGRect screenBounds = [[UIScreen mainScreen] bounds];

UINavigationBar  *navBar = [[UINavigationBar alloc]initWithFrame:CGRectMake(0, 0, screenBounds.size.width, 44)];
UINavigationItem *navItems = [[UINavigationItem alloc]init];
UIBarButtonItem *barButtonRight = [[UIBarButtonItem alloc]initWithTitle:@"" style:UIBarButtonItemStylePlain target:self action:@selector(SettingsButtonPressed)];
UISegmentedControll *segControl = [[UISegmentedControl alloc]initWithItems:[NSArray arrayWithObjects:@"Opt1",@"Opt2",@"Opt3", nil]];
UIImage *imageSettings= [UIImage imageNamed:@"36-toolbox.png"];

[segControl setSegmentedControlStyle:UISegmentedControlStyleBar];
[segControl setSelectedSegmentIndex:0];
[segControl setFrame:CGRectMake(10, 5, 150, 32)];
[segControl addTarget:self action:@selector(KiesVC:) forControlEvents:UIControlEventValueChanged];

[barButtonRight setImage:imageSettings];

[navItems setRightBarButtonItem:barButtonRight];
[navItems setTitleView:segControl];

[navBar setItems:[NSArray arrayWithObject:navItems] animated:NO];

次に、次のように呼び出してツールバーを追加します。

[self.view addSubview:navBar];

それが役に立てば幸い

于 2013-04-25T08:28:48.880 に答える