This is a question about IOS, XCode, Auto Layout and Objective-C, I think this is an easy answer, But I have searched high and low and can not get the solution.
I have a small Crosr having images as users pan around the map like in a Google Maps image is frozen I just Google map view a GMSMapView which I Having done an IBOutlet, self.mapView is doing this by adding a UIImageView as a subview.
I image the calculation of space with:
crosshairs.center = CGPointMake (self.mapView.bounds.size.width / 2, self.mapView.bounds .size.height / 2);
In the meantime, I have set barriers on the map's view so that its leading and trailing spaces can be evaluated for supervision. It should make breadth and height liquid - or so I thought.
In fact, when I width of the map view at runtime and height Anselog, they width (600) and height (384) as specified in the shape inspector in Xcode -. Even if I have not pinned with width or height barriers
The result is that the image is not centered for the screen, but to the wrong width and height of the map view (which is the screen )
I know that I'm looking at some idiots, or I do not remember the concepts of auto-layout. Anyhow, I appreciate any guidance.
Will
Important When using automatic layout, do you have to manually The frame should not be changed again (using the setCenter:
in your code) you should take everything from the obstacles.
You can add UIImage
to the storyboard at the top of the map and limit it there, using constraints.
If this is not possible, then you can add constraints in code using something like this:
[self.mapView addSubview: crosshairs]; [Crosshair set traceletsautorerisingingsmusent consultants: no]; [Self.mapView addConstraints: [NSLayoutConstraint constraintWithItem: self.mapView Feature: NSLayoutAttributeCenterY Related: NSLayoutRelationEqual toItem: crosshairs attribute: NSLayoutAttributeCenterY Multiplier: 1.0 continuous: 0]]; [Self.mapView addConstraints: [NSLayoutConstraint constraintWithItem: self.mapView feature: NSLayoutAttributeCenterX relatedBy: NSLayoutRelationEqual toItem: crosshairs featuring: NSLayoutAttributeCenterX multiplier: 1.0 constant: 0]];
Depending on where these constraints are being added, you may have to call [self.mapView layoutIfNeeded];. Using a deficiency of
, the map should always be centered on the top of the map view.
Regarding the wrong frame for the map view, it depends on whether you are entering it. If your IBOutlet
in a UIViewController
, then in viewWillLayoutSubviews should:
Pu after
[Super viewWillLayoutSubviews];
- (zero) VisualVilueLatSub view {{Super View attributes attributes}; NSLog (@ "Map View Frame% @", NSSSingFromCegrate (SELFMapviewFrame)); }
If you put it in a custom UIView
category, then you should check the frame in the layout: SUBviews:
- (zero) layout previews {[Super layout slides]; NSLog (@ "Map View Frame% @", NSSSingFromCegrate (SELFMapviewFrame)); }
Hope this fixes your problem.
No comments:
Post a Comment