kyleplattner
kyleplattner

Reputation: 633

Is it possible to present a modal view controller on the iPad without dimming the background?

I would like to present a modal view controller that doesn't dim the content behind it. Just using the standard presentViewController. Just adding the subview of the view controller to the parent view causes problems.

Upvotes: 2

Views: 1091

Answers (4)

Ely
Ely

Reputation: 9141

When using iOS 15 or newer, you can use this to prevent dimming of a modal view controller:

modalController.sheetPresentationController?.largestUndimmedDetentIdentifier = .large

Set this property before calling the present method.

Upvotes: 0

matax
matax

Reputation: 41

Try this:

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

    // remove the dimming view if needed, when this view controller will appear as modal
    id <UIViewControllerTransitionCoordinator> transitionCoordinator = self.transitionCoordinator;
    if (transitionCoordinator.presentationStyle != UIModalPresentationNone) {
        for (UIView *transitionContainerSubview in transitionCoordinator.containerView.subviews) {
            if ([NSStringFromClass([transitionContainerSubview class]) isEqualToString:@"UIDimmingView"]) {
                transitionContainerSubview.hidden = YES;
            }
        }
    }
}

Upvotes: 2

THE_DOM
THE_DOM

Reputation: 4296

Best bet is to add a view as a subview rather than as a modal viewController. I don't know your particular use, but from the sounds of it the logic should be in the same controller anyway.

myControllerThatWasModal.view.layer.opacity = 0.0f;
myControllerThatWasModal.view.hidden = YES;
[self.view addSubview:myControllerThatWasModal.view];
[UIView animateWithDuration:1.0 animations:^{
     myControllerThatWasModal.view.layer.opacity = 1.0f;   
}];

This was written from memory so forgive any mistakes, and also not that for this to work you need to have an instance of your "modal" view controller in the view controller that it will cover.

Upvotes: 0

Zack Brown
Zack Brown

Reputation: 6028

Have a look at UIModalPresentationStyle perhaps?

typedef NS_ENUM(NSInteger, UIModalPresentationStyle) {
UIModalPresentationFullScreen = 0,
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_3_2
UIModalPresentationPageSheet,
UIModalPresentationFormSheet,
UIModalPresentationCurrentContext,
#endif
};

You can specify the type of modal presentation using setModalPresentationStyle: on your view controller before calling presentViewController:animated:completion:.

Upvotes: 0

Related Questions