2017-03-03 102 views
0

这里是我的ViewController实现:简单的Google地图应用 - 如何调整容器大小?

@implementation ViewController 

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


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

    - 
    (void) loadView { 
      // Create a GMSCameraPosition that tells the map to display the 
      // coordinate -33.86,151.20 at zoom level 6. 
      GMSCameraPosition * camera = [GMSCameraPosition cameraWithLatitude: -33.86 
        longitude: 151.20 
        zoom: 6 
      ]; 
      GMSMapView * mapView = [GMSMapView mapWithFrame: CGRectZero camera: camera]; 
      mapView.myLocationEnabled = YES; 
      self.view = mapView; 

      // Creates a marker in the center of the map. 
      GMSMarker * marker = [ 
        [GMSMarker alloc] init 
      ]; 
      marker.position = CLLocationCoordinate2DMake(-33.86, 151.20); 
      marker.title = @ "Sydney"; 
      marker.snippet = @ "Australia"; 
      marker.map = mapView; 
    } 

    @end 

我如何可以调整这个窗口,因为现在它跨越整个屏幕?我希望它更小,因此它适合位于顶部状态栏下方的较小的框中。

回答

0

创建一个UIView并添加MapView类为子视图

UIView *yourView = [[UIView alloc] initWithFrame:CGRectMake(10, 64, 200, 200)]; 
    [self.view addSubview:yourView]; 

只需更换

GMSMapView * mapView = [GMSMapView mapWithFrame: CGRectZero camera: camera]; 

GMSMapView * mapView = [GMSMapView mapWithFrame: yourView.bounds camera: camera]; 

同时更换

self.view = mapView; 

[yourView addSubview:mapView]; 
+0

对于最后一个,[testView addSubview:mapView] ;,我的编译器表示使用未声明的标识符“testView”。 – nincs12

+0

我的错误用yourview替换它 – Developer

+0

感谢它编译。但是,现在它只是一个空白的白屏(谷歌地图不加载)。 – nincs12

0

改变这一行:

self.view = mapView; 

要:

[self.view addSubview:mapView]; 
mapView.frame = CGRectMake(0, 64,300, 300);// Set your Expected size here. 

您的问题背后的原因是要设置mapView作为你的主要观点 所以它采取mainView大小并显示到全屏。

希望这会帮助你改变你的mapView大小。

+0

它说未声明标识符“addSubView” – nincs12

+0

对不起错字错误尝试'[self.view addSubview:mapView];' – CodeChanger

+0

无法正常工作。空白的白色屏幕 – nincs12

相关问题