因此,我正在开发一个简单的应用程序,其中我使用了表视图。此表视图显示了"players“的名称。但为了让我在表视图中添加球员,我希望显示一个弹出窗口,其中包含一个文本字段,您可以在其中提供名称。
现在,我一直在阅读有关创建xib或nib文件的内容,但我不确定如何“加载”弹出窗口。
解决这个问题的最好方法是什么?
看起来像这样:


发布于 2015-11-30 04:11:35
你需要用所有需要的对象创建一个定制的UIView,然后在你的控制器的viewDidLoad()中隐藏它。
customView.hidden = true每当你的用户想要执行某项操作或任务时,你可以将其取消隐藏,一旦用户完成,然后再次隐藏它,或者从superView中删除它。
customView.hidden = false下面有一些代码可以帮助您入门
private var customView: UIView!
override func viewDidLoad() {
super.viewDidLoad()
customView.hidden = true
}
private func loadCustomViewIntoController() {
let customViewFrame = CGRect(x: 0, y: 0, witdh: view.frame.width, height: view.frame.height - 200)
customView = UIView(frame: customViewFrame)
view.addSubview(customView)
customView.hidden = false
// any other objects should be tied to this view as superView
// for example adding this okayButton
let okayButtonFrame = CGRect(x: 40, y: 100, width: 50, height: 50)
let okayButton = UIButton(frame: okayButtonFrame )
// here we are adding the button its superView
customView.addSubview(okayButton)
okayButton.addTarget(self, action: #selector(self.didPressButtonFromCustomView:), forControlEvents:.TouchUpInside)
}
func didPressButtonFromCustomView(sender:UIButton) {
// do whatever you want
// make view disappears again, or remove from its superview
}
@IBAction func rateButton(sender:UIBarButtonItem) {
// this barButton is located at the top of your tableview navigation bar
// when it pressed make sure you remove any other activities that were on the screen, for example dismiss a keyboard
loadCustomViewIntoController()
}看看这个github project,它已经关闭,准备投入生产了,它为您提供了处理(呈现和取消) UIViews的更好方法
如果您只想要球员的名字,则使用包含文本字段
的UIAlertController
发布于 2017-03-23 19:32:55
情节提要中的
在故事板中创建一个
自定义类anotherViewController和Storyboard_ID设计它一个新的可可触摸类作为anotherViewController和UIVIewController的子类
viewController中的
let popvc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "another_view_sid") as! anotherViewController
self.addChildViewController(popvc)
popvc.view.frame = self.view.frame
self.view.addSubview(popvc.view)
popvc.didMove(toParentViewController: self)anotherViewController中的
override func viewDidLoad() {
super.viewDidLoad()
showAnimate()
}
}
@IBAction func Close_popupView(_ sender: Any) {
removeAnimate()
}
func showAnimate()
{
self.view.transform = CGAffineTransform(scaleX: 1.3, y: 1.3)
self.view.alpha = 0.0
UIView.animate(withDuration: 0.25, animations: {
self.view.alpha = 1.0
self.view.transform = CGAffineTransform(scaleX: 1.0, y: 1.0)
})
}
func removeAnimate()
{
UIView.animate(withDuration: 0.25, animations: {
self.view.transform = CGAffineTransform(scaleX: 1.3, y: 1.3)
self.view.alpha = 0.0
}, completion: {(finished : Bool) in
if(finished)
{
self.willMove(toParentViewController: nil)
self.view.removeFromSuperview()
self.removeFromParentViewController()
}
})
}发布于 2018-06-08 17:16:02
此第三方EzPopup (https://github.com/huynguyencong/EzPopup)可以帮助您展示它。只需在故事板中设计弹出窗口,然后初始化它。
// init YourViewController
let contentVC = ...
// Init popup view controller with content is your content view controller
let popupVC = PopupViewController(contentController: contentVC, popupWidth: 100, popupHeight: 200)
// show it by call present(_ , animated:) method from a current UIViewController
present(popupVC, animated: true)https://stackoverflow.com/questions/33987442
复制相似问题