【问题标题】:UIPopover equal screen width弹出框等于屏幕宽度
【发布时间】:2014-12-21 03:22:59
【问题描述】:

我需要使弹出框大小等于设备屏幕宽度,可以吗?我试试这样的代码:

ShareViewController *shareVC = [[ShareViewController alloc] init];
sharePopover = [[UIPopoverController alloc] initWithContentViewController:shareVC];
sharePopover.popoverContentSize = shareVC.view.frame.size; // width there is 1024 i'm sure
sharePopover presentPopoverFromRect:CGRectMake(sender.frame.origin.x, sender.frame.origin.y + 10, sender.frame.size.width, sender.frame.size.height) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];

我也尝试在popoverContentSize 中设置宽度,如1024 或更大,但没有效果,我的左右两边有一些空格,我该如何解决?

这里的问题截图: http://uaimage.com/image/c54d471d

【问题讨论】:

  • 如果您想要这种完全控制,请考虑使用弹出框以外的其他东西。为什么不是呈现的视图控制器?在 iOS 7 和 8 中,很容易让呈现的视图出现在主视图的前面,就像弹出框一样。你所拥有的甚至看起来都不像一个弹出框,所以你根本不清楚为什么要使用它。
  • @matt 在我的情况下使用 popover 更舒服,因为我不需要编写动画来显示和隐藏他,但这不是主要问题,总而言之我决定使用 popover,如果没有解决方案,我会使用 UIView 或 UIViewController,谢谢。

标签: ios objective-c ipad uipopovercontroller


【解决方案1】:

来自 Apple 的 UIPopoverController 文档,关于“popoverLayoutMargins”属性(可在此处找到:UIPopoverController documentation:

The margins that define the portion of the screen in which  
it is permissible to display the popover....
...The edge inset values are measured in points from the edges of the screen,  
relative to the current device orientation...  
...The default edge insets are 10 points along each edge.  

尝试添加以下内容,看看是否有帮助:

sharePopover.popoverLayoutMargins = UIEdgeInsetsZero;

【讨论】:

  • 完美适用于IOS7,但不适用于IOS8,但总比没有好,谢谢。
  • @matt 文档没有说明它在 iOS 8 中被弃用。这是一个错误吗?
  • @AMI289 我当然认为这是一个错误。
猜你喜欢
  • 1970-01-01
  • 2021-10-13
  • 2011-12-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-12-21
相关资源
最近更新 更多