iphone - 按钮中的 presentPopoverFromRect 超出范围

标签 iphone objective-c ios ipad uipopovercontroller

所以我使用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。理论上,弹出框应显示在不会超出的浅灰色范围内。

enter image description here

最佳答案

对于包含在弹出框内的 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/

相关文章:

iphone - 当没有要删除的单元格时,如何关闭 UITableView 中的编辑模式?

iphone - 合并暂定定义时 iOS 对齐丢失

iphone - NSData 附加数据 : UIImageJPEGRepresentation() returns nil

ios - Html5 Canvas : Can I draw really sharp on non-retina devices like iPad2?

ios - 由于 libWeANDSFLibrary.a(ASIReachability.o) 而导致的重复符号链接(symbolic link)器错误

ios - SKAction 暂停播放声音循环

ios - 如何在 "dd/MM/yyyy"格式 ios 中获取 NSDate?

ios - 如何获取将要呈现的 HTML 字符串的高度?

ios - 子类化静态库中的类

iphone - 无法关闭模态视图 Controller