My app has a monthly view and for each day in the month, on a long press, a popover is displayed.
我的应用程序具有月视图,并且对于该月中的每一天,长按,显示弹出窗口。
I have used self.view setExclusiveTouch:YES
to prevent more than one popover occurring at once but that still occasionally allows multiple popovers.
我使用了self.view setExclusiveTouch:YES来防止一次发生多个popover但仍然偶尔会允许多个popover。
How can I prevent more than one UIPopover from being displayed at a time?
如何防止一次显示多个UIPopover?
Thanks
3 个解决方案
#1
3
First of all declare a property of type UIPopoverController (lets say activePopover).
首先声明一个UIPopoverController类型的属性(比如activePopover)。
In the method that is called on long press do this:
在长按调用的方法中执行以下操作:
if (self.activePopover != nil)
{
if (self.activePopover.popoverVisible)
[ self.activePopover dismissPopoverAnimated:YES];
self.activePopover = nil;
}
And then when you allocate the UIPopoverController on long press assign it to activePopover. This way you always dismiss a visible popover and only then present a new one.
然后在长按分配UIPopoverController时将其分配给activePopover。这样你总是会忽略一个可见的弹出窗口,然后才会出现一个新的弹出窗口。
#2
0
You can disable any interactions outside popover by setting its passthroughViews
property to empty array after its presentation.
您可以通过在其显示后将其passthroughViews属性设置为空数组来禁用popover外的任何交互。
#3
0
What about a global boolean flag?
全局布尔标志怎么样?
Create it as a property in a global class or in your viewcontroller and check it before opening any popup
在全局类或viewcontroller中将其创建为属性,并在打开任何弹出窗口之前进行检查
Init it with FALSE
value and when you are going to open a popup just check its value:
使用FALSE值初始化它,当您打开弹出窗口时,只需检查其值:
//In the method that handle the long press to open the popup
if(!self.popUpPresent)
{
//open the pop up
[self openNewPopUp];
//put the flag
self.popUpPresent = TRUE;
}
else
//There is a popup opened, do another stuff or nothing.
Dont forget to reset it value again to FALSE
every time you close a popUp.
每次关闭popUp时,别忘了再次将其值重置为FALSE。
Hope it helps
希望能帮助到你
#1
3
First of all declare a property of type UIPopoverController (lets say activePopover).
首先声明一个UIPopoverController类型的属性(比如activePopover)。
In the method that is called on long press do this:
在长按调用的方法中执行以下操作:
if (self.activePopover != nil)
{
if (self.activePopover.popoverVisible)
[ self.activePopover dismissPopoverAnimated:YES];
self.activePopover = nil;
}
And then when you allocate the UIPopoverController on long press assign it to activePopover. This way you always dismiss a visible popover and only then present a new one.
然后在长按分配UIPopoverController时将其分配给activePopover。这样你总是会忽略一个可见的弹出窗口,然后才会出现一个新的弹出窗口。
#2
0
You can disable any interactions outside popover by setting its passthroughViews
property to empty array after its presentation.
您可以通过在其显示后将其passthroughViews属性设置为空数组来禁用popover外的任何交互。
#3
0
What about a global boolean flag?
全局布尔标志怎么样?
Create it as a property in a global class or in your viewcontroller and check it before opening any popup
在全局类或viewcontroller中将其创建为属性,并在打开任何弹出窗口之前进行检查
Init it with FALSE
value and when you are going to open a popup just check its value:
使用FALSE值初始化它,当您打开弹出窗口时,只需检查其值:
//In the method that handle the long press to open the popup
if(!self.popUpPresent)
{
//open the pop up
[self openNewPopUp];
//put the flag
self.popUpPresent = TRUE;
}
else
//There is a popup opened, do another stuff or nothing.
Dont forget to reset it value again to FALSE
every time you close a popUp.
每次关闭popUp时,别忘了再次将其值重置为FALSE。
Hope it helps
希望能帮助到你