2

弹出框的首选尺寸仅在高度大于 320 时有效。

我已经搜索了很多来解决这个问题。但没有找到任何答案。弹出框在 iPad 中是否应满足任何最小尺寸?如果没有,我错过了什么?

代码:

UIViewController *viewController = [subStoryboard instantiateViewControllerWithIdentifier:SMFormViewControllerSBID];
controller = [[UINavigationController alloc] initWithRootViewController:viewController];

SMFormViewController *formViewController = (SMFormViewController *)controller.topViewController;
formViewController.modalPresentationStyle = UIModalPresentationPopover;
formViewController.preferredContentSize = CGSizeMake(375, 320);

popController = [controller popoverPresentationController];
popController.permittedArrowDirections = UIPopoverArrowDirectionLeft;
popController.delegate = self;

popController.sourceView = tblDocDetails;
NSInteger section = [tblDocDetails numberOfSections] - 1;
CGRect rectCustomLoc = [tblDocDetails rectForFooterInSection:section];
popController.sourceRect = CGRectMake(rectCustomLoc.origin.x, rectCustomLoc.origin.y, 130, rectCustomLoc.origin.y/2);

[self presentViewController:controller animated:YES completion:nil];

注意: 我试过了,adaptivePresentationStyleForPresentationController:&adaptivePresentationStyleForPresentationController:返回UIModalPresentationNone

4

2 回答 2

1

我的弹出窗口有时不可见,因为sourceRect不正确。

由于我在导航控制器中嵌入了 ViewController,preferredContentSize因此应该设置为导航控制器。

controller.preferredContentSize = CGSizeMake(375, 100);

& 在ViewController 中:

self.navigationController.preferredContentSize = contentsize;

并更改sourceRect为:

CGRect rectCustomLoc = [table rectForFooterInSection:section];
rectCustomLoc.size.width = sender.frame.size.width;
popController.sourceRect = rectCustomLoc;
于 2018-03-14T05:15:42.760 回答
1

我尝试了以下方法:

- (void)viewDidLoad {
    [super viewDidLoad];

    self.view.backgroundColor = [UIColor whiteColor];

    UIButton *btnOpen = [UIButton buttonWithType:UIButtonTypeCustom];
    [btnOpen setFrame:CGRectMake(100, 100, 100, 44)];
    [btnOpen setTitle:@"POP" forState:UIControlStateNormal];
    [btnOpen setBackgroundColor:[UIColor grayColor]];
    [btnOpen addTarget:self action:@selector(btnOpen:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btnOpen];
}

- (void)btnOpen:(id)sender {
    UIView *sourceView = (UIButton *)sender;

    UIViewController *vc = [[UIViewController alloc] initWithNibName:nil bundle:nil];
    vc.modalPresentationStyle = UIModalPresentationPopover;
    vc.preferredContentSize = CGSizeMake(150, 150);
    [self presentViewController:vc animated:YES completion:nil];

    UIPopoverPresentationController *popVc = vc.popoverPresentationController;
    popVc.permittedArrowDirections = UIPopoverArrowDirectionLeft;
    popVc.sourceView = sourceView;
    popVc.sourceRect = sourceView.bounds;
}

结果是这样的(iPad Air 2,iOS 11.2):

150x150 弹出框

这是基于您的示例的解决方案,我认为您使用 GCD 显示弹出框可能会导致问题...

    UIViewController *viewController = [subStoryboard instantiateViewControllerWithIdentifier:SMFormViewControllerSBID];
    controller = [[UINavigationController alloc] initWithRootViewController:viewController];
    controller.modalPresentationStyle = UIModalPresentationPopover;
    controller.preferredContentSize = CGSizeMake(375, 320);

    [self presentViewController:controller animated:YES completion:nil];

    popController = [controller popoverPresentationController];
    popController.permittedArrowDirections = UIPopoverArrowDirectionLeft;
    popController.delegate = self;

    popController.sourceView = tblDocDetails;
    NSInteger section = [tblDocDetails numberOfSections] - 1;
    CGRect rectCustomLoc = [tblDocDetails rectForFooterInSection:section];
    popController.sourceRect = CGRectMake(rectCustomLoc.origin.x, rectCustomLoc.origin.y, 130, rectCustomLoc.origin.y/2);
于 2018-03-05T13:09:41.893 回答