2017-03-03 40 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

相關問題