Question

I usually do apps for iPhone ; today I try to create an interface for the app (universal binary). The issue is I have screens with few controls and I would like to adapt the interface, with UIModalPresentationFormSheet. But after the screen which uses this kind of presentation I would like to switch back to fullscreen (using the same navigation controller).

Initially on the iPhone part I have UINavigationController -> sub controllers. As it is the same class controllers, I would like to keep a similar architecture for the iPad. Currently I do the following UINavigationController -> ModalController -> UINavigationController -> sub controllers But as explained above, the sub controllers should been able to switch from FormSheet to fullscreen, with the navigation bar on the top. I'm using the storyboard.

And as I know I'm not really good for explanations, here is a screenshot that should clarify my issue : https://dl.dropbox.com/u/9858108/stack_overflow_iPad_nav_issue.jpg

Was it helpful?

Solution

Ok, I found a dirty solution but that fixed the problem. I have the following configuration NavigationController -> UIViewController -[Modal]-> UINavigationController -> UIViewController1 -[Push]-> UIViewController2 (check the screenshot above).

Now the idea is to resize the ModalView (I force landscape mode, so portrait is not supported but you can easily modify the code). I have a singletton class that contain useful methods, I called AppKit. In AppKit.m :

#pragma mark - Window functions (modal, ...)

/**
 * Cette méthode redimmensionne une modal view en type PaperSheet.
 * Utilisé dans le viewDidAppear du controller enfant.
 * Permet de mettre des modal view en fullscreen.
 *
 * @param id viewController Le viewController parent
 */
- (void)resizeModalToPaperSheet:(id) viewController {
    // Adaptation de la taille de la fenêtre pour iPad
    if (isIPad) {
        [viewController navigationController].view.superview.center = CGPointMake(0.0f, 0.0f);
        [viewController navigationController].view.superview.frame = CGRectMake(84.0f, 242.0f, 540.0f, 540.0f);
    }
}

/**
 * Cette méthode redimmensionne une modal view en type FullScreen.
 * Utilisé dans le viewDidAppear du controller enfant.
 * Permet de mettre des modal view en fullscreen.
 *
 * @param id viewController Le viewController parent
 */
- (void)resizeModalToFullScreen:(id) viewController {
    // Adaptation de la taille de la fenêtre pour iPad
    if (isIPad) {
        [viewController navigationController].view.superview.center = CGPointMake(0.0f, 0.0f);
        [viewController navigationController].view.superview.frame = CGRectMake(20.0f, 0.0f, 754.0f, 1024.0f);
    }
}

Now in my sub viewcontrollers I have to call the method two times (else when you press back the size of the modalview is keeped from the previous controller, so you have to put it in viewDidAppear).

ViewController 1 (PaperSheet size) :

-(void) viewWillAppear:(BOOL)animated {
    [[AppKit sharedInstance] resizeModalToPaperSheet: self];
}

-(void) viewDidAppear:(BOOL)animated {
    [[AppKit sharedInstance] resizeModalToPaperSheet: self];
}

ViewController 1 (FullScreen size) :

-(void) viewWillAppear:(BOOL)animated {
    [[AppKit sharedInstance] resizeModalToFullScreen: self];
}

-(void) viewDidAppear:(BOOL)animated {
    [[AppKit sharedInstance] resizeModalToFullScreen: self];
}

And it works pretty good ; I can easily switch between fullscreen and PaperSheet. Now there is one remaining problem : On the storyboard, view is still small, and it's not easy to add stuff inside. So you have to do this : 1/ In the storyboard, click on the view controller which is to small (box icon) 2/ On the attributes panel, set the size to iPad fullscreen

Hope this helps, any comment on how to improve the code is welcome :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top