簡體   English   中英

如何從GMSMapView更改myLocationButton位置?

[英]How to change myLocationButton position from a GMSMapView?

有人知道如何從GMSMapView實例獲取myLocationButton的實例嗎? 還是一種改變默認位置的方法? 我只需要將它移動一些像素。

根據問題5864的問題跟蹤器:錯誤:GMSMapView填充似乎不適用於AutoLayout有一個更簡單的解決方法:

- (void)viewDidAppear:(BOOL)animated {
  // This padding will be observed by the mapView
  _mapView.padding = UIEdgeInsetsMake(64, 0, 64, 0);
}

Raspu的解決方案可以移動整個GMSUISettingsView,包括指南針。

我找到了一個只移動位置按鈕的解決方案:

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;
        */
    }
};

如果取消注釋三條線,則只移動指南針(由於某種原因,我無法移動GMSCompassButton視圖)。

Swift 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)
  }
}

我會盡快將此代碼更新到Swift 3.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版本。 對於以前的版本,請為@"UIButton"更改@"GMSUISettingsView" @"UIButton"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM