UIModalPresentationFormSheet, dim is missing

1.8k views Asked by At

I am trying to display a modal viewController in an iPad app using the UIModalPresentationFormSheet view style. I am looking to produce something similar to the Mail app's new message UI/animation.

There are two things that are not behaving correctly: The modal viewController that is presented always animates to y=0, i.e. to the very top of the view and not some pixels below the status bar as it does in the mail app.

The documentation says:

UIModalPresentationFormSheet The width and height of the presented view are smaller than those of the screen and the view is centered on the screen. If the device is in a landscape orientation and the keyboard is visible, the position of the view is adjusted upward so that the view remains visible. All uncovered areas are dimmed to prevent the user from interacting with them.

However, in my case there is no dimming and I can still interact with the parentView below the modalViewController.

The controller that presents the modalView I do this:

AddNewItemViewController *newItemViewController = [[AddNewItemViewController alloc] initWithNibName:@"AddNewItemViewController" bundle:nil];
[self presentModalViewController:newItemViewController animated:YES];
[newItemViewController release];

In the viewController being presented I do this:

- (void)viewDidLoad {

    [nameField becomeFirstResponder];
    [self setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
    [self setModalPresentationStyle:UIModalPresentationFormSheet];
    [super viewDidLoad];
}

I hope someone can help me out.

Is there some other properties I need to set on the parent and modalViewController?

Is the viewDidLoad not the right place to do this setup?

Thanks in advance:)

1

There are 1 answers

1
W Dyson On BEST ANSWER

You set the transition and presentation styles when you create the modal view, before you call presentModalViewController. Remember, the view that creates the modal view 'owns' that object. You want the owner to set these properties because you might implement this modal view elsewhere in the app and want different transition or presentation styles. This way, you set it each time as appropriate.

    AddNewItemViewController *newItemViewController = [[AddNewItemViewController alloc] initWithNibName:@"AddNewItemViewController" bundle:nil];
    newItemViewController.modalPresentationStyle = UIModalPresentationFormSheet;
    [self presentModalViewController:newItemViewController animated:YES];
    [newItemViewController release];

You're right in calling becomeFirstResponder in viewDidLoad.