xcode 如何在 Swift 中创建弹出视图
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27313431/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to create a pop up view in Swift
提问by sky1995
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
我希望它看起来像右边的图片
回答by User31
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)
}
}