sky1995
sky1995

Reputation: 43

how to create a pop up view in Swift

So I am trying to create a pop up view within an existing view: Whenever a button is pushed, the pop up view comes up

this is the code I've used to when the button is pressed

@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 use 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 labels and they seem to overlap when the view comes up. I don't know how to fix it. I am not sure if there is an easier away but I've been stuck on this problem for a while.

I want it to look something like the picture on the right

enter image description here

Upvotes: 3

Views: 13870

Answers (1)

User31
User31

Reputation: 279

Popover should be presented from 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)

}

Upvotes: 1

Related Questions