Present UIViewController as UIModalPresentationFormSheet & UIModalPresentationOverCurrentContext

590 views Asked by At

How do I present a UITableViewController with a blurred background as a form sheet over the current context?

- (void)viewDidLoad {

   self.tableView.backgroundColor = [UIColor clearColor];
   self.tableView.backgroundView = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
}

It works fine full screen, on iPhones set with UIModalPresentationOverCurrentContext

But for iPad if I want to display it as a form sheet then I need to set modalPresentationStyle to UIModalPresentationFormSheet.

How do I set both?

2

There are 2 answers

0
Chris On BEST ANSWER

I found I needed to use UIModalPresentationPopoverfor the modalPresentationStyle and then you can set the view controllers popoverPresentationColor to clearColor.

 FAGalleryTableViewController *vc = (FAGalleryTableViewController *)[segue destinationViewController];

        if ( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ) {
            vc.modalPresentationStyle = UIModalPresentationPopover;
            vc.popoverPresentationController.sourceView = _storeButton;
            vc.popoverPresentationController.backgroundColor = [UIColor clearColor];
            vc.popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirectionDown;
            vc.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
    }
0
Reza.Ab On

After searching so much, this worked for me on iOS10+

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
            //IPAD
            CamVC *destination = segue.destinationViewController;
            [destination setModalPresentationStyle:UIModalPresentationFullScreen];
            [destination setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];

        }else{
            // IPHONE
            CamVC *destination = segue.destinationViewController;
            destination.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;
            destination.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
        }