将 UIViewController 呈现为 UIModalPresentationFormSheet 和 UIModalPresentationOverCurrentContext

Present UIViewController as UIModalPresentationFormSheet & UIModalPresentationOverCurrentContext

如何在当前上下文中以 sheet 形式呈现具有模糊背景的 UITableViewController?

- (void)viewDidLoad {

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

它在设置为 UIModalPresentationOverCurrentContext

的 iPhone 上全屏运行良好

但是对于iPad,如果我想将其显示为sheet形式,那么我需要将modalPresentationStyle设置为UIModalPresentationFormSheet

如何设置两者?

我发现我需要为 modalPresentationStyle 使用 UIModalPresentationPopover,然后您可以将视图控制器 popoverPresentationColor 设置为 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;
    }

经过大量搜索后,这对我有用 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;
        }