Размер содержимого ViewController не меняет размер поповера

Предпочтительный размер поповера работает только в том случае, если высота больше 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,

2 ответа

Решение

Мой поповер иногда не виден из-за sourceRect было неверно.

Поскольку я встроил ViewController в контроллер навигации, preferredContentSize следует установить в Navigation Controller.

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;

Я попробовал следующее:

- (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);
Другие вопросы по тегам