我想在所有设备和所有方向上的弹出窗口中始终显示视图控制器.我试图通过采用UIPopoverPresentationControllerDelegate并设置sourceView和sourceRect来实现这一目标.故事板中的segue被配置为Present A
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { let popoverPresentationController = segue.destinationViewController.popoverPresentationController popoverPresentationController?.delegate = self popoverPresentationController?.sourceView = self.titleLabel!.superview popoverPresentationController?.sourceRect = self.titleLabel!.frame } func adaptivePresentationStyleForPresentationController(controller: UIPresentationController) -> UIModalPresentationStyle { return UIModalPresentationStyle.None }实现new(从iOS 8.3开始)adaptivePresentationStyleForPresentationController:traitCollection:UIAdaptivePresentationControllerDelegate的方法:
- (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller traitCollection:(UITraitCollection *)traitCollection { // This method is called in iOS 8.3 or later regardless of trait collection, in which case use the original presentation style (UIModalPresentationNone signals no adaptation) return UIModalPresentationNone; }
UIModalPresentationNone告诉演示控制器使用原始演示样式,在您的情况下将显示弹出窗口.