任何人都知道如何從GMSMapView實例中獲取myLocationButton的實例嗎?或者改變默認位置的方法?我只需要將它移動一些像素。如何更改GMSMapView中的myLocationButton位置?
回答
根據本Issue 5864: Bug: GMSMapView Padding appears not to work with AutoLayout的問題跟蹤器還有一個更簡單的解決方法:
- (void)viewDidAppear:(BOOL)animated {
// This padding will be observed by the mapView
_mapView.padding = UIEdgeInsetsMake(64, 0, 64, 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"
。
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;
*/
}
};
。
你說得對,你的回答更準確,所以我給你發票。 – Raspu
這個答案改變google圖標的位置不知道怎麼沒有羅盤按鈕 – ahmedHegazi
你能告訴我如何移動GMSCompassButton? –
雨燕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。 :)
SWIFT 3請 –
- 1. 如何在swift中更改Google地圖的myLocationButton的位置
- 2. 在iOS中的Google地圖中更改MyLocationButton的位置
- 3. mylocationButton不更新我的位置爲什麼?
- 4. 如何重新定位Xamarin表單中myLocationButton和true North按鈕的位置?
- 5. GMSMapView中myLocation沒有給實際位置
- 6. 如何更改android中imageview的位置?
- 7. 如何更改UISearchBar中的UITextField位置?
- 8. 如何更改FF中的iframe位置
- 9. 如何更改JFrame中JLabel的位置?
- 10. 如何更改Emacs中的minibuffer位置?
- 11. 如何更改wordpress位置
- 12. 如何更改gitconfig位置?
- 13. 如何更改admob位置
- 14. 如何更改MessageBox位置?
- 15. 如何更改錨位置
- 16. 如何更改UITabBarItem位置?
- 17. 如何設置在Storyboard中定義的GMSMapView對象的中心位置
- 18. 如何更改Firefox的位置設置
- 19. 更改的位置,$位置
- 20. 如何將光標位置更改爲VB中的picturebox位置
- 21. 如何在php中更改'echo'位置?
- 22. 如何在RStudio中更改.Rprofile位置
- 23. 如何在Eclipse中更改AVD位置
- 24. 如何在ColumnLayout中更改位置
- 25. 位置更改的Android位置更新
- 26. 如何更改應用欄的位置?
- 27. 如何更改groovysh.profile的默認位置?
- 28. 如何更改此塊的位置?
- 29. 如何更改NSPopover的箭頭位置?
- 30. 如何更改UINavigationBar的位置?
即使這將對所有用戶界面應用填充,這似乎是自1.5開始的方式,所以我會將該門票移至您。 – Raspu