我正在使用UIPopoverPresentationController并分配对象,如下面的代码,
UIPopoverPresentationController *presentationController =
[myPopoverViewController popoverPresentationController];
我只想检查弹出窗口是否在另一种方法中可见。早先在UIPopoverController中有popoverVisible可用,有没有替代方案。而且我想在其他一些方法中解雇它是否有任何替代dismissPopoverAnimated。? 我只是想做这样的事情
if (presentationController != nil && presentationController.popoverVisible)
{
[presentationController dismissPopoverAnimated:YES];
}
任何帮助表示感谢。
谢谢
答案 0 :(得分:1)
试试这个
设置为
popoverPresentationController.delegate = self;
[presentationController dismissViewControllerAnimated:YES completion:nil]; // or use self
并使用
的委托方法# pragma mark - Popover Presentation Controller Delegate
- (void)popoverPresentationControllerDidDismissPopover:(UIPopoverPresentationController *)popoverPresentationController {
// called when a Popover is dismissed
}
- (BOOL)popoverPresentationControllerShouldDismissPopover:(UIPopoverPresentationController *)popoverPresentationController {
// return YES if the Popover should be dismissed
// return NO if the Popover should not be dismissed
return YES;
}
- (void)popoverPresentationController:(UIPopoverPresentationController *)popoverPresentationController willRepositionPopoverToRect:(inout CGRect *)rect inView:(inout UIView *__autoreleasing _Nonnull *)view {
// called when the Popover changes position
}
样本请参阅此tutorial
答案 1 :(得分:0)
所有UIViewController
现在都有isBeingPresented
属性,因此请检查UIPopoverPresentationController
myPopoverViewController
是否有效。
if myPopoverViewController.isBeingPresented {
myPopoverViewController.dismiss(animated: true, completion: nil)
}