2013-04-28 92 views

回答

3

不是很正统,但它的工作原理。

for (UIView *view in gmMapView.subviews) { 
     NSRange isRange = [view.description rangeOfString:@"GMSCompassButton"]; 
     if (isRange.location != NSNotFound) { 
      CGRect frame = view.frame; 
      frame.origin.y=55; 
      frame.origin.x=gmMapView.frame.size.width/2; 
      [view setFrame:frame]; 
     } 
    } 
+1

这不适合我。我通过打印子视图看到日志,没有“GMSCompassButton”项目。 – regeint 2014-11-07 05:42:20

0

寻找“GMSCompassButton”的解决方法不再适用(Google Maps SDK 1.4)。

+0

原因是“GMSCompassButton”现在被包裹在另一个名为“GSMUISettingsView”的子视图中。你将不得不添加另一套for循环来使其工作。 – 2013-09-25 15:06:48

0

以下是适用于SDK 1.5的最新解决方法。

- (void)moveCompassButton:(GMSMapView *) map{ 
    for(UIView *view in [map subviews]){ 
     NSRange isRange = [view.description rangeOfString:@"GMSUISettingsView"]; 
     if(isRange.location != NSNotFound){ 
      for(UIView *subview in [view subviews]){ 
       NSRange isRange2 = [subview.description rangeOfString:@"GMSCompassButton"]; 
       if(isRange2.location != NSNotFound){ 
        CGRect frame = view.frame; 
        frame.origin.y = 55; 
        frame.origin.x = map.frame.size.width/2 - 10; 
        [view setFrame:frame]; 
       } 
      } 
     } 
    } 
} 

您可以使用您的地图视图作为参数调用此函数,并且您可以轻松前往。

0

新版本的Google Maps SDK 1.5包含GMSMapView的paddern属性。 现在可以设置显示UI元素的区域。

4
-(void)viewDidAppear:(BOOL)animated{ 
mapView.padding = UIEdgeInsetsMake (64,0,0,0); 
} 

此代码它将以64像素向下移动指南针按钮。