简体   繁体   English

UIPopovercontroller与UIButton分离

[英]UIPopovercontroller detached from UIButton

I'm running into a problem with a detached UIPopovercontroller and am hoping someone has seen this behavior before. 我遇到了一个分离的UIPopovercontroller的问题,我希望有人之前已经看到过这种行为。

My app runs in Landscape mode and offers a number of popover elements using the presentPopoverFromRect call. 我的应用程序在横向模式下运行,并使用presentPopoverFromRect调用提供了许多弹出框元素。 Some are launched from within the top view while others are presented from a view buried deep in the display. 一些是从顶视图中启动的,而另一些是从深埋在显示器中的视图中呈现的。 The popovers seem to work fine if the popover is presented from the upper 2/3rds of the iPad's display however when attempting to launch a popover from the bottom 1/3 of the display the popover is displayed detached from the UIButton. 如果弹出窗口是从iPad显示器的上部2/3处呈现的话,弹出窗口似乎工作正常,但是当试图从显示器的底部1/3启动弹出框时,弹出窗口显示为与UIButton分离。 The x coordinate appears to be correct, however the y coordinate of the popover tends to be in the middle or top of the iPad screen. x坐标似乎是正确的,但是弹出窗口的y坐标往往位于iPad屏幕的中间或顶部。

I've played around with presenting the popover using a fixed position by creating a CGRect object in the lower 1/3 of the display but when the iPad renders the popover it either renders the popover in the upper 2/3rd of the view or the very bottom of the screen (if I force the CGRect value to a large y value). 我通过在显示屏的下1/3处创建一个CGRect对象来演示使用固定位置的弹出窗口,但是当iPad呈现弹出窗口时,它会在视图的上部2/3处呈现弹出窗口或者屏幕的最底部(如果我将CGRect值强制为大的y值)。

At this point I'm out of ideas and hoping someone on the forum has seen this or can make suggestions as to what to try. 在这一点上,我没有想法,希望论坛上有人看到这个,或者可以就如何尝试提出建议。

Thanks for any and all help, Wes 谢谢你的帮助,Wes

I was able to fix my issue and thought that I'd share my solution incase someone else has the same problem. 我能够解决我的问题,并认为我会分享我的解决方案,因为其他人有同样的问题。

The solution was to add a call to set the popover size BEFORE calling presentPopoverFromRect. 解决方案是在调用presentPopoverFromRect之前添加一个调用以设置弹出框大小。

[mySettingsPopoverController setPopoverContentSize:CGSizeMake(320, 320) animated:YES];
[mySettingsPopoverController presentPopoverFromRect:sender.frame inView:self.navigationButtonsView permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

Before, I wasn't setting the popover content size prior to presenting the popover. 之前,我没有在呈现弹出窗口之前设置弹出窗口内容大小。 In the viewDidAppear method of the viewcontroller of the popover I was resizing the popover to size to the tableview in the popover. 在popover的viewcontroller的viewDidAppear方法中,我将popover的大小调整为popover中的tableview的大小。 Apparently by not setting the popovercontentsize before presenting the popover you get undefined behavior including the possibility of having the popover detach from the element that it is suppose to be attached to. 显然,通过在呈现弹出窗口之前不设置popovercontentsize,您会得到未定义的行为,包括可能将弹出窗口从要连接的元素中分离出来。

Wes 韦斯

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM