弹出框控制器出现问题。视图控制器被呈现为模式弹出框。指向锚点的箭头需要为红色,因此我设置了背景色:
vc.modalPresentationStyle = UIModalPresentationPopover;
vc.popoverPresentationController.backgroundColor = [UIColor primaryColor];
弹出框的下角从背景颜色开始是红色。
Edit 11/06
当vc设置为模式弹出框时,vc角由弹出框自动舍入,并且弹出框背景被暴露。但是,它对vc的舍入与弹出窗口的舍入不匹配。
这是意外的。我找不到任何可以设置角半径的方法。我尝试将视图控制器的view和collectionView的cornerRadius设置为0,但是拐角保持不变,并且popoverPresentationController仍然显示红色。任何想法如何解决此问题?
最终将UIPopoverBackgroundView子类化以定位和绘制箭头,并将其类分配给popoverPresentationController.popoverBackgroundViewClass。
在UIPopoverBackgroundView的子类中
- (void)layoutSubviews
{
[super layoutSubviews];
for (UIView* subview in self.superview.subviews)
{
if (subview != self && subview.layer.cornerRadius > 0)
{
subview.layer.cornerRadius = self.cornerRadius; // cornerRadius - your custom property
subview.clipsToBounds = YES;
}
}
}
也许您可以找到更好的位置而不是layoutSubviews。