简体   繁体   English

在Swift 3.0中无法将View Controller显示为弹出控制器

[英]Not able to show a View Controller as pop up controller in Swift 3.0

I'm trying to add my view controller as pop up controller. 我正在尝试将我的视图控制器添加为弹出控制器。 But everyt ime i use the code the view comes sliding from bottom and not as i wish. 但是,每当我使用代码时,视图就会从底部滑动,而不是我希望的那样。 Below is the code i'm using 下面是我正在使用的代码

    let storyboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
    let popupVC = storyboard.instantiateViewController(withIdentifier: "WSFilterViewController") as! WSFilterViewController
    popupVC.modalPresentationStyle = UIModalPresentationStyle .popover
    popupVC.preferredContentSize = CGSize (width: 300, height:300)
    let pVC = popupVC.popoverPresentationController
    pVC?.permittedArrowDirections = UIPopoverArrowDirection.any
    pVC?.delegate = self as? UIPopoverPresentationControllerDelegate
    self.present(popupVC, animated: true, completion: nil)

I want it as in the image shown 我想要它,如图所示

在此处输入图片说明

Any help will be appreciated. 任何帮助将不胜感激。

Thanks in advance 提前致谢

let storyboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
    let popupVC = storyboard.instantiateViewController(withIdentifier: "WSFilterViewController")
    popupVC.modalPresentationStyle = UIModalPresentationStyle .popover
    popupVC.preferredContentSize = CGSize(width: 170, height: 130)
    popupVC.popoverPresentationController?.delegate = self
    popupVC.popoverPresentationController?.sourceView = sender as? UIView // button
    popupVC.popoverPresentationController?.sourceRect = (sender as AnyObject).bounds
    self.present(popupVC, animated: true, completion: nil)

The issue was something different and figured it out now. 问题有所不同,现在就解决了。

Thanks everyone 感谢大家

 func adaptivePresentationStyle(for controller: UIPresentationController, traitCollection: UITraitCollection) -> UIModalPresentationStyle
{
    return .none
}

you must add the code above on iPhone devices, otherwise it will keep showing full screen. 您必须在iPhone设备上添加以上代码,否则它将保持全屏显示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM