I implemented a small mapView (65×65) in a scrollView in a viewController. If i set the Position of the mapView per XIB and run it on the Simulator or iOS Devices it is not sitting on the right Position:
- XIB right position
- iPhone 5 to high
- iPhone 4 (or Simulator) much to high
I can correct the position for each situation with these codes, but this cant be the solution:
Code for the same Position in the XIP:
CGRect newFrameMapView = CGRectMake(10,171,65,65);
mapView.frame = newFrameMapView;
Code to correct it for the output on iPhone 5:
CGRect newFrameMapView = CGRectMake(10,215,65,65);
mapView.frame = newFrameMapView;
Code to correct it for the output on iPhone 4:
CGRect newFrameMapView = CGRectMake(10,302,65,65);
mapView.frame = newFrameMapView;
Notes:
- I have got a navigationController on the top.
- Nothing changes if i put the mapView out of the scrollView.
- I dont use Autolayout
— Edit — 23.01.2013 ———————————–
I ‘ve renamed the “mapView” into “mapView2” to make sure not to change the position on other parts of my code.
Here are the important code fragments of the .h
#import <MapKit/MapKit.h>
@interface ViewControllerDetail : UIViewController <MKMapViewDelegate> {
IBOutlet MKMapView *mapView2;
}
@property(nonatomic, retain) IBOutlet MKMapView *mapView2;
@end
and the .m
@implementation ViewControllerDetail
@synthesize mapView2;
[…]
// Basic Settings Map
[mapView2 setMapType:MKMapTypeStandard];
[mapView2 setZoomEnabled:NO];
[mapView2 setScrollEnabled:NO];
[mapView2 setDelegate:self];
// Map Start
MKCoordinateRegion myStartRegion = { {0.0, 0.0}, {0.0, 0.0} };
myStartRegion.center.latitude = 44.087439;
myStartRegion.center.longitude = 2.139614;
myStartRegion.span.latitudeDelta = 0.003;
myStartRegion.span.longitudeDelta = 0.003;
[mapView2 setRegion:myStartRegion animated:NO];
// Map Point
MKCoordinateRegion myBeispielRegion = { {0.0, 0.0}, {0.0, 0.0} };
myRegion1.center.latitude = 44.087439;
myRegion1.center.longitude = 2.139614;
classAnnotation *annotationRegion1 = [[classAnnotation alloc] init];
annotationRegion1.coordinate = myRegion1.center;
[mapView2 addAnnotation:annotationRegion1];
I found the mistake:
(Dunno if this is normal, i use Xcode Version 4.5)
If i insert an MapView in the Xib it is automatically set on Autosizing left/bottom. I didn’t noticed that, i thought the standard autosizing is left/top.