2013-06-19 43 views

回答

0

現在我已經找到了唯一的辦法是這樣的:

//The method 'each' is part of Objective Sugar 
[googleMapView.subviews each:^(UIView *object) { 
    if([[[object class] description] isEqualToString:@"GMSUISettingsView"]) 
    { 
     CGPoint center = object.center; 
     center.y -= 40; //Let's move it 40px up 
     object.center = center; 
    } 
}]; 

它的正常工作,但正式的方式會更好。

這適用於1.4.0版本。對於以前的版本,請將@"GMSUISettingsView"更改爲@"UIButton"

4

Raspu的解決方案移動了包括指南針在內的整個GMSUISettingsView。

我發現了一個解決方案,只移動位置按鈕:如果取消對三行只移動指南針(由於某種原因,我不能移動GMSCompassButton查看)

for (UIView *object in mapView_.subviews) { 
    if([[[object class] description] isEqualToString:@"GMSUISettingsView"]) 
    { 
     for(UIView *view in object.subviews) { 
      if([[[view class] description] isEqualToString:@"UIButton"]) { 
       CGRect frame = view.frame; 
       frame.origin.y -= 75; 
       view.frame = frame; 
      } 
     } 
     /*   
     CGRect frame = object.frame; 
     frame.origin.y += 75; 
     object.frame = frame; 
     */ 
    } 
}; 

+0

你說得對,你的回答更準確,所以我給你發票。 – Raspu

+0

這個答案改變google圖標的位置不知道怎麼沒有羅盤按鈕 – ahmedHegazi

+0

你能告訴我如何移動GMSCompassButton? –

2

雨燕2.3:解決方案只移動位置按鈕。我使用pod'GoogleMaps','〜> 2.1'。

for object in mapView.subviews { 
    if object.theClassName == "GMSUISettingsView" { 
     for view in object.subviews { 
      if view.theClassName == "GMSx_QTMButton" { 
       var frame = view.frame 
       frame.origin.y = frame.origin.y - 110px // Move the button 110 up 
       view.frame = frame 
      } 
     } 
    } 
} 

擴展名以獲取類名。

extension NSObject { 
    var theClassName: String { 
    return NSStringFromClass(self.dynamicType) 
    } 
} 

我會盡快更新此代碼雨燕3.0。 :)

+0

SWIFT 3請 –