Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Popup UIViewController

Tags:

I'm trying to make a popup which will be presented by pressing a button. Tried to follow instructions which i found in google but my pop view presenting in a full screen and its background is black. Here is my code:

class ViewController: UIViewController, UIPopoverPresentationControllerDelegate {

    @IBAction func someButtonPressed(sender: UIButton) {
        let storyboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
        let popupVC = storyboard.instantiateViewControllerWithIdentifier("hello") as! popupViewController
        popupVC.modalPresentationStyle = .Popover
        popupVC.preferredContentSize = CGSizeMake(300, 300)
        let pVC = popupVC.popoverPresentationController
        pVC?.permittedArrowDirections = .Any
        pVC?.delegate = self
        pVC?.sourceView = sender
        pVC?.sourceRect = CGRect(x: 100, y: 100, width: 1, height: 1)
        presentViewController(popupVC, animated: true, completion: nil)
    }
}

What I'am doing wrong?

like image 712
Ookey Avatar asked May 13 '16 09:05

Ookey


1 Answers

To make your view controller shown as a popup, you should set the following:

popupVC.modalPresentationStyle = .OverCurrentContext
popupVC.modalTransitionStyle = .CrossDissolve

You should also design your view controller's position, size to make it look like a popup.

Here is my popup that i did before.

enter image description here

like image 105
Tien Avatar answered Dec 23 '22 13:12

Tien