Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 207
jaytrixz Avatar asked Dec 29 '12 11:12

jaytrixz


2 Answers

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;
like image 85
wattson12 Avatar answered Nov 11 '22 05:11

wattson12


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 ! :-)

like image 1
Raphaël Avatar answered Nov 11 '22 06:11

Raphaël