Ger*_*rep 6 cocoa-touch objective-c ios swift
我有一个登录按钮的视图.单击该按钮时,我添加了一个包含用于登录的字段的视图.发生这种情况时,我需要调暗父视图.我怎么做的?
斯威夫特2
UIViews有一个名为的财产maskView.
maskView将永远位于拥有它的UIView之上.
所以,你的方法应该是这样的(这适用于Swift,但它很容易转换为Obj-c):
self.view.maskView = UIView(frame: self.view.frame)
self.view.maskView?.backgroundColor = UIColor.blackColor().colorWithAlphaComponent(0.5)
//Do your work here, block UI, anything you need to, and then...
self.view.maskView = nil
Run Code Online (Sandbox Code Playgroud)
斯威夫特3
属性名称已更改为mask.
self.view.mask = UIView(frame: self.frame)
self.view.mask?.backgroundColor = UIColor.black.withAlphaComponent(0.5)
//Do your work here, block UI, anything you need to, and then...
self.view.mask = nil
Run Code Online (Sandbox Code Playgroud)