所以我使用WEPopover显示自定义 View Controller 弹出。我有一个 UIView,其中有另一个 UIView,称为 containerView。在这个 containerView 里面,我有一个 UIButton。这就是我想展示我的popover的地方。所以这就是我所做的:
[self.popoverDialog presentPopoverFromRect:sender.frame inView:self.containerView permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
问题是该按钮显示了箭头和所有内容,但弹出框超出了 self.containerView 的范围。如何使弹出框显示在 containerView 范围内?
编辑:
一张图片胜过一千个字,所以这里是:
浅灰色的是我上面提到的containerView。理论上,弹出框应显示在不会超出的浅灰色范围内。
最佳答案
对于包含在弹出框内的 View ,转到它的 View Controller 并设置它的属性 contentSizeForViewInPopover。在这里您可以设置大小,使其适合您的 containerView 的边界。
OP 希望定位弹出框,使其仅显示在他的容器 View 中。我在 WEPopoverController.m 文件中找到了这段代码
- (void)repositionPopoverFromRect:(CGRect)rect
inView:(UIView *)theView
permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections {
CGRect displayArea = [self displayAreaForView:theView];
WEPopoverContainerView *containerView = (WEPopoverContainerView *)self.view;
[containerView updatePositionWithAnchorRect:rect
displayArea:displayArea
permittedArrowDirections:arrowDirections];
popoverArrowDirection = containerView.arrowDirection;
containerView.frame = [theView convertRect:containerView.frame toView:backgroundView];
}
您可能会调用此方法,它可能会重新定位您的弹出框,以便它现在位于您的容器 View 中。
关于iphone - 按钮中的 presentPopoverFromRect 超出范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11768185/