ios - 关闭时获取 UIPopoverPresentationController 的事件
<p><p>我有 viewControllerA,我从中展示了显示静态数据的 <code>UIPopoverPresentationcontroller</code>。
请查看以下代码以获取更多信息。</p>
<pre><code>- (void)openPopupScreen:(id)sender {
PopupViewController *popupVC = ;
popupVC.delegate = self;
popupVC.preferredContentSize = CGSizeMake(220.0f, 230.0f);
popupVC.modalPresentationStyle = UIModalPresentationPopover;
_popupView = popupVC.popoverPresentationController;
self.popupView.delegate = self;
self.popupView.sourceView = self.view;
self.popupView.backgroundColor = ;
CGRect rect = CGRectMake(0.0f, 0.0f, 220.0f, 230.0f);
self.popupView.sourceRect = rect;
;
}
</code></pre>
<p>因为我没有编写关闭“弹出” View 的代码,因为当我简单地触摸 View 时它会自动关闭。</p>
<p>所以我的问题是当弹出窗口被关闭时我需要该事件。</p>
<p>提前致谢。</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>因为您已经使用以下语句应用了 <code>UIPopoverPresentationControllerDelegate</code> 的委托(delegate)。</p>
<pre><code>self.popupView.delegate = self;
</code></pre>
<p><strong>UIPopoverPresentationControllerDelegate 方法列表。</strong></p>
<p>1) 当弹出框 Controller 关闭弹出框时在委托(delegate)上调用。返回 NO 以防止
//关闭 View 。</p>
<pre><code>- (BOOL)popoverPresentationControllerShouldDismissPopover:(UIPopoverPresentationController *)popoverPresentationController;
</code></pre>
<p>2) 当用户采取行动关闭弹出框时在委托(delegate)上调用。以编程方式关闭弹出框时不会调用此方法。</p>
<pre><code>- (void)popoverPresentationControllerDidDismissPopover:(UIPopoverPresentationController *)popoverPresentationController;
</code></pre>
<p>3) 通知代理弹出框即将呈现。</p>
<pre><code>- (void)prepareForPopoverPresentation:(UIPopoverPresentationController *)popoverPresentationController;
</code></pre>
<p>更多信息请查看<a href="https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIPopoverPresentationControllerDelegate_protocol/index.html" rel="noreferrer noopener nofollow">Apple Developer link</a> .</p>
<p>供您引用 <code>popoverPresentationControllerDidDismissPopover</code> 将在您关闭弹出窗口时调用。</p>
<p>希望它对你有用。</p></p>
<p style="font-size: 20px;">关于ios - 关闭时获取 UIPopoverPresentationController 的事件,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/38265378/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/38265378/
</a>
</p>
页:
[1]