How to create a popup in Swift

So I am trying to create a popup view in an existing view: whenever a button is clicked, the popup opens

this is the code i used when the button is clicked

@IBAction func addFees(sender: UIButton) {
    UIView.beginAnimations(nil, context: nil)
    UIView.setAnimationDuration(0.3)
    view2.frame = CGRectMake(0, 200, 320, 261)
    UIView.commitAnimations()
}

      

this is the code i am using to make it go away

@IBAction func doneButton(sender: UIBarButtonItem) {
    UIView.beginAnimations(nil, context: nil)
    UIView.setAnimationDuration(0.3)
    listingfees.frame = CGRectMake(0, 1000, 320, 261)
    UIView.commitAnimations()
}

      

The problem is that I have other buttons and shortcuts and they seem to overlap when the view opens. I don't know how to fix this. I'm not sure which is easier, but I lingered on this issue for a while.

I want it to look like the picture on the right

enter image description here

+3


source to share


1 answer


Popover must be presented from the base view controller if you want it to be on top

@IBAction func addFees(sender: UIButton){
let viewController =  "Your Popover View Controller class"
viewController.modalPresentationStyle = .Popover
viewController.preferredContentSize = CGSizeMake(320, 261)

let popoverPresentationViewController = viewController.popoverPresentationController
popoverPresentationViewController?.permittedArrowDirections = .Any
popoverPresentationViewController?.delegate = self
popoverPresentationController?.sourceRect = sender.frame
presentViewController(playerInformationViewController, animated: true, completion: nil)

      



}

+1


source







All Articles