Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8649487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:34:27+00:00 2026-06-12T13:34:27+00:00

I have a MapView in a xib that is connected to Outlet. I set

  • 0

I have a MapView in a xib that is connected to Outlet. I set the frame by code for the portrait and the landscape. The frame is correct but the output is wrong. Why?

This is my code in MapViewController.h:

  @interface MapViewController : UIViewController <MKMapViewDelegate>{

  }

  @property (nonatomic, strong)UIImageView * imageView;
  @property (nonatomic, strong)IBOutlet UIButton * buttonHome;
  @property (nonatomic, strong)IBOutlet UIButton * buttonMap;
  @property (nonatomic, strong)IBOutlet UIButton * buttonFavorites;
  @property (nonatomic, strong)IBOutlet UILabel * labelTitle;
  @property (nonatomic, strong)IBOutlet MKMapView *mapView;

and MapViewController.m

  @implementation MapViewController

  @synthesize imageView;
  @synthesize buttonFavorites;
  @synthesize buttonHome;
  @synthesize buttonMap;
  @synthesize labelTitle;
  @synthesize mapView;

  - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
    // Custom initialization
}
return self;
 }

 -(void) layoutPortrait {

self.imageView= [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bar_V.png"]];
self.imageView.frame= CGRectMake(self.view.bounds.origin.x, self.view.bounds.origin.y, self.view.bounds.size.width, 80);
self.imageView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
self.labelTitle.frame =CGRectMake(14, 83, 121, 54);
self.buttonFavorites.frame= CGRectMake(109, 485, 33, 33);
self.buttonHome.frame =CGRectMake(14, 485, 33, 33);
self.buttonMap.frame=CGRectMake(61, 485, 33, 33);
self.mapView.frame = CGRectMake(0, 140, 320, 310);


}

-(void) layoutLandscape {

self. imageView= [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bar_O.png"]];
self.imageView.frame= CGRectMake(self.view.bounds.origin.x, self.view.bounds.origin.y,self.view.bounds.size.width,70 );
self.imageView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
self.labelTitle.frame =CGRectMake(20,72,140,48);

self.buttonFavorites.frame= CGRectMake(107,237,33,33);
self.buttonHome.frame =CGRectMake(11,237,33,33);
self.buttonMap.frame=CGRectMake(59,237,33,33);
self.mapView.frame = CGRectMake(201,65,367,227);


}


 - (void)viewDidLoad
{
[super viewDidLoad];


UIInterfaceOrientation deviceOrientation= self.interfaceOrientation;

if(deviceOrientation == UIInterfaceOrientationPortrait || deviceOrientation== UIInterfaceOrientationPortraitUpsideDown) {
    [self layoutPortrait];

}
else if (deviceOrientation== UIInterfaceOrientationLandscapeRight){
    [self layoutLandscape];

}
else if (deviceOrientation==UIInterfaceOrientationLandscapeLeft){

    [self layoutLandscape];

}

[self.view addSubview:self.imageView];
[self.view addSubview:self.mapView];
[self.view addSubview:self.labelTitle];
[self.view addSubview:self.buttonHome];
[self.view addSubview:self.buttonMap];
[self.view addSubview:self.buttonFavorites];


self.mapView.delegate=self;
}

 -(void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
UIDeviceOrientation deviceOrientation = [[UIDevice currentDevice]orientation];

if(self.imageView){
    [self.imageView removeFromSuperview];

}

if(deviceOrientation == UIInterfaceOrientationPortrait || deviceOrientation== UIInterfaceOrientationPortraitUpsideDown) {
    [self layoutPortrait];

}
else if (deviceOrientation== UIInterfaceOrientationLandscapeRight){
    [self layoutLandscape];

}
else if (deviceOrientation==UIInterfaceOrientationLandscapeLeft){

    [self layoutLandscape];

}

[self.view addSubview:self.mapView];
[self.view addSubview:self.labelTitle];
[self.view addSubview:self.imageView];
[self.view addSubview:self.buttonFavorites];
[self.view addSubview:self.buttonHome];
[self.view addSubview:self.buttonMap];


 }

What am I doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T13:34:28+00:00Added an answer on June 12, 2026 at 1:34 pm

    A couple of things:

    1) Do you have auto-size on your MKMapView on the xib file? That could interfere to what you are doing on code.

    2) You should handle rotation logic in the correct place and not in viewDidLoad. On the UIViewController Class reference, check the part Handling View Rotations, so you can see where to put your code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So i have an xib that has some UILabels and 1 MKMapView but the
I'm developing on an app that is location-based, I have a mapView set to
In my viewDidLoad: method I have set the MapView like this so that if
I have a MapView where Drawable markers are placed with a limit set to
I have a MapView that will contain alot of overlays. For this i've extended
I have a simple mapview that has the following viewdidload method and didupdate to
I have a mapview in my xib. -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch
I have a mapView with a detail disclosure indicator that when touched needs to
I have a mapView outlet on my view (MKMapViewDelegate) with Shows user location enabled.
I have a NavigationController in MainWindow.xib. It loads a RootViewController that basically manages a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.