本文介绍了触摸后解除Popover的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我在 MainViewController 中创建了一个popover,当使用 UIPopoverPresentationController 触及某个按钮并设置为类似2014年WWDC展会上的代表通过以下方式展示:I've created a popover inside my MainViewController when some button its touched using the UIPopoverPresentationController and set like it's delegate like it's showed in the WWDC 2014, in the following way :class MainViewController : UIViewController, UIPopoverPresentationControllerDelegate { @IBAction func showPopover(sender: AnyObject) { var popoverContent = self.storyboard?.instantiateViewControllerWithIdentifier("PopOverViewController") as UIViewController popoverContent.modalPresentationStyle = UIModalPresentationStyle.Popover var popover = popoverContent.popoverPresentationController popoverContent.preferredContentSize = CGSizeMake(250, 419) popover!.delegate = self popover!.sourceView = self.view popover!.sourceRect = CGRectMake(180,85,0,0) self.presentViewController(popoverContent, animated: true, completion: nil) }} popover里面有一个View,当用Tap Gesture Recognizer点击View时,我显示 LastViewController 使用模态segue,模态segue是通过Interface Builder创建的,而不是代码使用动作来呈现另一个 LastViewControllerThe popover have a View inside it and when the View it's clicked with a Tap Gesture Recognizer I show LastViewController using a modal segue, the modal segue is created through the Interface Builder, not in code using an action to present the another LastViewController一旦 LastViewController 被解雇,我回到 MainViewController popover仍处于打开状态。Once the LastViewController is dismissed and I'm back in the MainViewController the popover remains open.在 PopOverController 中,我只有默认代码。Inside the PopOverController I only have the default code nothing more.@IBAction func dismissVIew(sender: AnyObject) { self.dismissViewControllerAnimated(true, completion: nil)}以上代码用于解除 LastViewController 触摸内部按钮后。The above code is used to dismiss the LastViewController once the button inside is touched.怎么能一旦另一个 LastViewController 它可见,或者在另一个 LastViewController 应该被打开之前我解雇了popover?How can I dismiss the popover once the another LastViewController it's visible, or before the another LastViewController should be opened?提前致谢推荐答案 我已经回答了同样的问题这里 。 情况有所不同,但解决方案是相同的I have already answer same problem over here.There scenario is different but solution is same您必须在完成当前视图控制器时编写用于关闭呈现视图控制器的代码。 在你的dismissVIew方法上写下以下代码 LastViewController.swiftYou have to write code for dismiss presented view controller on completion of current view controller.Write below code on your dismissVIew method of LastViewController.swift var tmpController :UIViewController! = self.presentingViewController; self.dismissViewControllerAnimated(false, completion: {()->Void in println("done"); tmpController.dismissViewControllerAnimated(false, completion: nil); }); 下载 link 这篇关于触摸后解除Popover的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-14 15:23