简体   繁体   中英

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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