我正在尝试使用新的UIPopoverPresentationController显示一个小的模式弹出窗口,虽然它或多或少可以工作,但它包含的弹出窗口气泡正以一种非常奇怪的方式被切断:

看起来底部少了一块,但我不知道为什么。
下面是我用来显示弹出窗口的代码(请注意,sourceView位于inputAccessoryView上):
UIViewController *popoverVC = [self.storyboard instantiateViewControllerWithIdentifier:@"profilePopover"];
popoverVC.preferredContentSize = CGSizeMake(300,120);
popoverVC.modalPresentationStyle = UIModalPresentationPopover;
self.profilePopoverController = popoverVC.popoverPresentationController;
self.profilePopoverController.delegate = self;
self.profilePopoverController.sourceView = self.chatBar.profilePictureButton;
self.profilePopoverController.sourceRect = self.chatBar.profilePictureButton.bounds;
self.profilePopoverController.permittedArrowDirections = UIPopoverArrowDirectionDown;
popoverVC.modalPresentationStyle = UIModalPresentationPopover;
[self presentViewController:popoverVC animated:YES completion:nil];发布于 2016-05-31 22:14:57
当我在一个片段中展示我自己的popover时,我遇到了这个问题,每次我认为我解决了它,它又突然出现了。
不过,我想我终于明白了。它似乎与目标控制器的preferredContentSize和popover控制器的sourceRect中的值有关。内容大小是我调整得最多的一个。
如果大小值不是整数(例如,它需要是2.0而不是2.5 ),或者它们不是偶数(因此可以是2.0,但不是1.0),就会发生这种情况。我已经包含了我的prepare for segue方法,其中我设置了所有内容。我希望我的弹出窗口大小与我的视图的总大小相关,但这应该适用于更多的场景。我的按钮大小(对于sourceRect)是固定的,所以我的测量碰巧可以工作,不需要类似的调整,但我猜同样的限制也适用于这里。
if let button = sender as? UIButton where segue.identifier == "FAQSegue" {
let fullViewSize = self.view.bounds
let controller = segue.destinationViewController
let popoverController = controller.popoverPresentationController
popoverController?.delegate = self
var w = round(fullViewSize.width * 0.85)
var h = round(fullViewSize.height * 0.85)
w = (w % 2 == 0) ? w : w + 1
h = (h % 2 == 0) ? h : h + 1
controller.preferredContentSize = CGSize(width: w, height: h)
// Set arrow position to middle of button
popoverController?.sourceRect = CGRectMake(button.bounds.width / 2.0, 5.0, 0.0, 0.0)
}我不能确定这些是导致这个问题的唯一原因,但它确实为我解决了所有iPhone屏幕尺寸的问题。
https://stackoverflow.com/questions/30698042
复制相似问题