Question

I'm trying to figure something that is going on with my Route-Me code using both the Xcode iPad 4.2 Simulator and the iPad 5 simulator and both simulators and giving different results. Here is a snippit of the code:

    //set size of the map view
    [self setMapView:[[[RMMapView alloc] initWithFrame:CGRectMake(0.0, 0.0, 1024, 768)] autorelease]];
    [mapView setBackgroundColor:[UIColor blackColor]]; 
    self.view = mapView; 
    //set locked on default location of view, currently on conus
    CLLocationCoordinate2D newLocation;
    newLocation.latitude = 37.83;
    newLocation.longitude = -96.58;
    [[mapView contents] moveToLatLong:newLocation]; 
    [[mapView contents] setZoom:4.5];

Then below I set the application to only use Landscape mode:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
         if (UIInterfaceOrientationIsLandscape(interfaceOrientation)) { return YES; } return NO;
 }

I run this code in Xcode's iPad Simulator 4.2 and I get this image below which looks perfect: looks good here

Then I run this same code on Xcode's iPad Simulator 5 and I get this weird image: This is weird

I'm confused aren't they supposed to yield the same results? or am I missing something here?

EDIT: I have set Initial interface orientation and supported interface orientations in my plist file to have landscape only.

EDIT2: I tried running it with the code below as is and it seemed to work but if you put the setZoom line into the code, the picture gets cut off again, see screenshot:

[self setMapView:[[RMMapView alloc] initWithFrame:CGRectMake(0.0, 0.0, 1024, 768)]];
[mapView setBackgroundColor:[UIColor grayColor]];
self.view = mapView;

enter image description here

This is getting really strange, once I add the line [mapView.contents setZoom:4.5]; it happens again with the missing right portion of the screen.

Was it helpful?

Solution

I have figured it out it seems I cannot assume I am modifying the size of the parent view. To solve this I needed to assign self.view to a parent controller first then subview the mapView:

UIView* parentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)];
parentView.autoresizesSubviews = YES;
self.view = parentView;

mapView = [[RMMapView alloc] initWithFrame:CGRectMake(0.0, 0.0, 1024, 768)];
[parentView addSubview:mapView]; 

CLLocationCoordinate2D newLocation;
newLocation.latitude = 37.83;
newLocation.longitude = -96.58;
[mapView.contents moveToLatLong:newLocation];

[mapView setBackgroundColor:[UIColor grayColor]];
[mapView.contents setZoom:4.5];

OTHER TIPS

When in landscape you need to reverse width and height.

RMMapView *baseMap = [[[RMMapView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.height, self.view.bounds.size.width)] autorelease];

Remember that the device retains its same height and width, your rect just needs to change for the changed orientation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top