2016-05-13 18 views
5

Próbuję zrobić wyskakujące okienko, które zostanie wyświetlone po naciśnięciu przycisku. Próbowałem postępować zgodnie z instrukcjami, które znalazłem w google, ale mój popowy widok przedstawia się na pełnym ekranie, a jego tło jest czarne. Oto mój kod:Popup UIViewController

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) 
    } 
} 

Co I'am robi źle?

Odpowiedz

16

Aby kontroler widok pokazany jako popup, należy ustawić następujące:

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

Należy również zaprojektować stanowisko Pana zdaniem regulatora, rozmiar, aby wyglądał jak popup.

Oto moje popup, które zrobiłem wcześniej.

enter image description here