弹出窗口的首选尺寸仅在高度大于320时才有效。
我已经搜索了很多来解决这个问题。但没有找到任何答案。是否有任何最小尺寸的popover应该在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
。
答案 0 :(得分: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):
以下是基于您的示例的解决方案,我认为您使用GCD来显示popover可能会导致问题......
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);
答案 1 :(得分:0)
我的popover有时看不到,因为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;