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
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
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)
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);
@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)
}
}
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
}
}
These methods no longer work on iOS 7. Correct way is to specify bottomLayoutGuide on your UIViewController. Described in detail here