设置 UIPopOverController 大小
我有一个 view
,其中有 UIScrollView
中的一堆按钮。当用户按下按钮时,我希望显示一个 UIPopOverController 指向所选按钮。它有点工作,但是弹出窗口的大小错误并且指向视图中的随机点。这是我的代码。
-(void)detail:(id)sender{
UIButton *button = sender;
NSLog(@"tag = %i", button.tag);
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:viewController];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
self.popover = [[UIPopoverController alloc] initWithContentViewController:navController];
self.popover.delegate = self;
[self.popover presentPopoverFromRect:button.bounds inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
比弹出窗口的大小问题: 在弹出窗口内的视图中,我有:
self.contentSizeForViewInPopover = scroll.contentSize;
NSLog(@"%f, %f", scroll.contentSize.height, scroll.contentSize.width);
NSLog(@"showing: %f, %f", self.contentSizeForViewInPopover.height, self.contentSizeForViewInPopover.width);
并且两个日志都匹配。所以我认为一切都应该正常进行。但事实并非如此。这是一个屏幕截图。如果您需要更多我的代码,请告诉我。提前致谢。
I have a view
with a bunch of button in a UIScrollView
. When the user presses a button, I want a UIPopOverController to display pointing at the selected button. It kind of works, but the popover is the wrong size and points to a random point in the view. Here is my code.
-(void)detail:(id)sender{
UIButton *button = sender;
NSLog(@"tag = %i", button.tag);
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:viewController];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
self.popover = [[UIPopoverController alloc] initWithContentViewController:navController];
self.popover.delegate = self;
[self.popover presentPopoverFromRect:button.bounds inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
Than the problem with the size of the popover:
In the view that is inside the popover, I have:
self.contentSizeForViewInPopover = scroll.contentSize;
NSLog(@"%f, %f", scroll.contentSize.height, scroll.contentSize.width);
NSLog(@"showing: %f, %f", self.contentSizeForViewInPopover.height, self.contentSizeForViewInPopover.width);
and both logs are matching. So I think everything should work correctly. But it doesn't. Here is a screen shot. Let me know if you need more of my code. Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我注意到的第一件事是,您应该对 from 矩形使用button.frame 而不是button.bounds。这些 UIView 属性之间的区别:
您可以使用其 popover 控制器设置高度<一href="http://developer.apple.com/library/ios/#documentation/uikit/reference/UIPopoverController_class/Reference/Reference.html#//apple_ref/occ/instm/UIPopoverController/setPopoverContentSize%3aanimated%3a">setPopoverContentSize消息:
First thing I noticed is that you should be using the button.frame not the button.bounds for the from rectangle. The difference between these UIView properties:
You can set the height of your popover controller using its setPopoverContentSize message:
仅关于弹出窗口的大小:我设法使用可变高度的 UILabel 来做到这一点:
对于箭头:您是否尝试过不同的 inView 参数,例如 self.parentViewController.view?
Regarding the size of the popover only: I managed to do it with a variable heighted UILabel:
And for the arrow: have you tried a different inView param like self.parentViewController.view?