How do you move the legal sign in mapview

后端 未结 11 2043
别跟我提以往
别跟我提以往 2020-12-05 20:24

I wonder if anyone know how you move the legal sign on a mapview, right now my toolbar is covering it. Does anyone know how? There is lot\'s of help with the google logo but

相关标签:
11条回答
  • 2020-12-05 20:25

    Carrying on Skeet Skeet point .

    I implemented your approach it worked well but after coming in the viewcontroller multiple times legal label y keeps on decreasing as you see the logic it always displaces itself. so instead changing centre i propose

    we change frame

    UILabel *attributionLabel = [mapView.subviews objectAtIndex:1];
        attributionLabel.frame = CGRectMake(20, self.view.frame.size.height - 135, attributionLabel.frame.size.width, attributionLabel.frame.size.height); 
    \\135 is height of your bottom view that was hiding legal
    
    0 讨论(0)
  • 2020-12-05 20:26

    Swift 4+

    You can change the position of those by setting the layoutMargins of the mapView.

    For example this will push it off from the bottom:

    mapView.layoutMargins.bottom = -100
    

    Also you can change edge insets you need all at once:

    mapView.layoutMargins = UIEdgeInsets(top: 0, left: 0, bottom: -100, right: 0)
    
    0 讨论(0)
  • 2020-12-05 20:38

    This is still possible in iOS 7, but only (?) if placed in viewDidAppear. The coords are reset if placed in viewDidLoad or viewWillAppear.

        UILabel *attributionLabel = [mapView.subviews objectAtIndex:1];
        attributionLabel.center = CGPointMake(attributionLabel.center.x, attributionLabel.center.y - 44.0f);
    
    0 讨论(0)
  • 2020-12-05 20:39

    @Dymtro's answer works well for me, but I would suggest checking the size of the subviews first. This should at least prevent possible crashes if the view hierarchy changes in the future:

    override func viewWillLayoutSubviews() {
        positionLegalMapLabel()
    }
    
    func positionLegalMapLabel() {
        if self.mapView.subviews.count > 1 {
            let legalMapLabel = self.mapView.subviews[1]
    
            legalMapLabel.frame.origin = CGPointMake(self.mapView.bounds.size.width - legalMapLabel.frame.size.width - 7, legalMapLabel.frame.origin.y)
        }
    }
    
    0 讨论(0)
  • 2020-12-05 20:41

    I wrote extension that worked for me. It can be used in animation block to animate those changes:

    import MapKit
    
    extension MKMapView {
    
      /// Workaround for layoutMargins bug.
      func setLegalInsets(left: CGFloat, bottom: CGFloat) {
        let oldLeft = layoutMargins.left
        let oldBottom = layoutMargins.bottom
    
        let lblLegal = (subviews.filter { view in
          return view is UILabel
          }).first
    
        lblLegal?.frame.origin.x += left - oldLeft
        lblLegal?.frame.origin.y -= bottom - oldBottom
    
        layoutMargins.left = left
        layoutMargins.bottom = bottom
      }
    }
    
    0 讨论(0)
  • 2020-12-05 20:44

    These methods no longer work on iOS 7. Correct way is to specify bottomLayoutGuide on your UIViewController. Described in detail here

    0 讨论(0)
提交回复
热议问题