jaytrixz
jaytrixz

Reputation: 4079

Adjusting MKMapView's Frame on iOS 6 in Objective-C

I'm trying to adjust the frame of my MKMapView created on IB for 4-inch devices but it doesn't work. Here's my code on viewDidLoad:

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.

    // Resizing UILabel for 4-inch screen
    CGRect screenBounds = [[UIScreen mainScreen] bounds];
    if (screenBounds.size.height == 568) // 4 inch
    {
        mapView.frame = CGRectMake(0, 44, 320, 504);
    }
    else // 3.5 inch
    {
        mapView.frame = CGRectMake(0, 44, 320, 416);
    }
    // END - Resizing UILabel for 4-inch screen
}

Can anyone tell me what's wrong with this setup? Thanks.

Upvotes: 5

Views: 4750

Answers (2)

Raphaël
Raphaël

Reputation: 91

I had the same issue with a static table View One cell included a MapView.

Different iphone Screen Size : Different cell height for the map view cell.

I looked at different approach like :

mapView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);  

Unfortunately for me , it only works when user re-orientate the mobile => redraw?

My solution was to correctly use the AUTO LAYOUT in IB and use contraint And it solved my issue

Left Horizontal Space Constraint = '0'
Right Horizontal Space Constraint = '0'
Top Vertical Space Constraint = '0'
Bottom Vertical Space Constraint = '0'

--> this is my first post in stackoverflow.com ! :-)

Upvotes: 1

wattson12
wattson12

Reputation: 11174

If you just want to set the mapView to be the same size as the view controllers view (i.e. fill the screen), set the map view's frame to be the bounds of the view, and give them the same autoresizing masks (you can do this in viewDidLoad and you shouldn't have to test for screen size)

mapView.frame = self.view.bounds;
mapView.autoresizingMask = self.view.autoresizingMask;

Upvotes: 6

Related Questions