gpt4 book ai didi

ios - 将模态视图放在 View 上并使背景变灰

转载 作者:行者123 更新时间:2023-11-29 01:40:37 26 4
gpt4 key购买 nike

过去 3 小时我一直在尝试完成此操作,但我不知道该怎么做。有人可以帮忙吗?

这就是我想要做的。当我按下一个按钮时,比如说,一个 Sign In 按钮,我希望弹出一个模态视图,使它后面的 View 变成灰色并且无法点击。在这个模态视图上,我想要几个按钮和静态标签。

我已经阅读并尝试理解一些资源,例如:Present modal view controller in half size parent controller , http://makeapppie.com/2014/08/30/the-swift-swift-tutorials-adding-modal-views-and-popovers/ , How to use modal views in swift? , 和其他几个。但是,我很难理解代码。

到目前为止,我有这段代码应该使模态视图位于它后面的 View 之上:

@IBAction func signIn(sender: AnyObject) {
self.modalTransitionStyle = UIModalTransitionStyle.CoverVertical
// Cover Vertical is necessary for CurrentContext
self.modalPresentationStyle = .CurrentContext
// Display on top of current UIView
self.presentViewController(SignInViewController(), animated: true, completion: nil)
}

但这并没有产生我想要的效果。有人帮忙吗?

最佳答案

首先,创建你的灰色空 View

func makeGrayView() -> UIView {
var view = UIView(frame:UIScreen.mainScreen().applicationFrame)
self.view.backgroundColor = UIColor.greyColor()
return view
}

其次,将您刚刚创建的 View 设置为叠加层的背景

var backView = self.makeGrayView()
self.view.addSubview(backView)

关于ios - 将模态视图放在 View 上并使背景变灰,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32433608/

26 4 0