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 7962519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:21:31+00:00 2026-06-04T05:21:31+00:00

I try to center a view which is displayed in my iPad App depending

  • 0

I try to center a view which is displayed in my iPad App depending on interface orientation.
That doesn’t work, the view is always shifted depending on in which orientation the app started.

I’ve searched through Stackoverflow for 2 hours now, tried different methods but couldn’t make it work.

This is how i display the view from root view:

publicationDownload = [[PublicationDownloadController alloc] init];
// Setting up propertys to load Publication-related information
[publicationDownload setDelegate:self];
[publicationDownload setThePubID:[NSNumber numberWithInt:[sender tag]]];

publicationDownload.view.opaque = NO;
publicationDownload.view.backgroundColor = [UIColor clearColor];
[publicationDownload.theUIView.layer setCornerRadius:5];
[publicationDownload.theUIView.layer setShadowColor:[UIColor blackColor].CGColor];
[publicationDownload.theUIView.layer setShadowOpacity:0.5];
[publicationDownload.theUIView.layer setShadowRadius:5];
[publicationDownload.theUIView.layer setShadowOffset:CGSizeMake(3.0f, 3.0f)];
publicationDownload.theUIView.clipsToBounds = NO;
publicationDownload.theUIView.backgroundColor = [UIColor clearColor];
[publicationDownload.theInnerUIView.layer setCornerRadius:5];
[publicationDownload.theInnerUIView.layer setShadowColor:[UIColor blackColor].CGColor];
[publicationDownload.theInnerUIView.layer setShadowOpacity:0.5];
[publicationDownload.theInnerUIView.layer setShadowRadius:5];
[publicationDownload.theInnerUIView.layer setShadowOffset:CGSizeMake(3.0f, 3.0f)];
[publicationDownload.theInnerUIView.layer setMasksToBounds:YES];
publicationDownload.theUIView.layer.masksToBounds = NO;
publicationDownload.view.clipsToBounds = YES;
publicationDownload.view.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:.5];

[self.view addSubview:publicationDownload.view];

within the publicationDownloadViewController i’ve implemented:

in viewDidLoad:
// Do any additional setup after loading the view from its nib.

//self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 
//self.view.contentMode = UIViewContentModeRedraw;
self.view.autoresizesSubviews = YES;
//self.view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
self.view.frame = self.view.bounds;
//theUIView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin;

NSLog(@"PublicationDownloadController: viewDidLoad:");
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRotate:) name:UIDeviceOrientationDidChangeNotification object:nil];    
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];

if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) {
    theUIView.frame = CGRectMake(212, 229, 600, 240);
    self.view.frame = CGRectMake(0, 0, 1024, 768);
} else if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) {
    theUIView.frame = CGRectMake(140, 380, 600, 240);
    self.view.frame = CGRectMake(0, 0, 768, 1024);
}

and additional:

-(void)didRotate:(NSNotification*)notification
{
    NSLog(@"PublicationDownloadController: didRotate");
UIDeviceOrientation oreo = [[UIDevice currentDevice] orientation];
// oreo is our new orientation!
if (oreo == UIInterfaceOrientationPortrait || oreo == UIInterfaceOrientationPortraitUpsideDown) {
    //theUIView.frame = CGRectMake(212, 229, 600, 240);
    self.view.frame = self.view.bounds;
} else if (oreo == UIInterfaceOrientationLandscapeLeft || oreo == UIInterfaceOrientationLandscapeRight) {
    //theUIView.frame = CGRectMake(140, 380, 600, 240);
    self.view.frame = self.view.bounds;
}
}

the View itself contains a view in landscape, which background is set to black and alpha 0.5 (in IB)-
Additional there is another View (theUIView) which holds some UIControls. This theUIView needs to be centered. It works if ste app starts in Landscape for the landscape view, but not if the orientation changes to portrait. Also if the app starts in portrait, the view is not displayed centered.

Any help is much appreciated!

  • 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-04T05:21:32+00:00Added an answer on June 4, 2026 at 5:21 am

    It was easier than expected. Dealing with autoresizemask in Interface Builder and cleaning some messy code did the job.

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

Sidebar

Related Questions

This is the code that won't work, when I try to view this page
I'm trying to create programatically a custom view controller with subviews which center on
In my iPad app, I have a UIButton that is calling an IBAction to
I'm try to change text color and align item in spinner to center of
Try to see which cast is faster (not necessary better): new c++ case or
try: spam.foo except AttributeError: do_somthing() (Is it wise to check an attribute like that
My application allows users to take photos with their devices camera app, which are
I have a App which uses the camera to take a picture. The camera
if someone have Instagram on his iPhone try to tap on the raised center
I am working on a simple GPS-like app. I created a custom object which

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.