Search code examples
iphoneipad

How to show iPhone size views on iPad applications


I have an iPhone application (app1) which has to be integrated as a sub-application on another universal iOS app (app2).

For various reasons I don't want to create an iPad interface for my iPhone app1, I just want that all the views will be shown with iPhone dimensions (at the center of the screen) also when the main app2 is executed on an iPad. On app1 I do not support landscape orientation, only portrait.

Is this somehow possible to realize? Thank you in advance.


Solution

  • This is the code!

    UIPopoverController *popoverController = [[UIPopoverController alloc] initWithContentViewController:yourViewController];
    [popoverController setPopoverContentSize:CGSizeMake(320, 480)];
    

    And to show the popoverController in the middle of the iPad screen

    UIDevice* thisDevice = [UIDevice currentDevice];    
    if(thisDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad){
        [popOverController presentPopoverFromRect:CGRectMake(380, 450, 1, 1) inView:self.view permittedArrowDirections:0 animated:YES];
    }
    

    To maintain always the same size of your UIPopoverController do not forget to set the contentSizeForViewInPopover in each view (do this inside the viewWillAppear:)

    - (void)viewWillAppear:(BOOL)animated{
    
    [self setContentSizeForViewInPopover:CGSizeMake(320, 480)];
    }