ログインボタンのあるビューがあります。ボタンをクリックすると、ログイン用のフィールドを含むビューが追加されます。これが発生した場合、親ビューを暗くする必要があります。どうすればいいですか?
5388 次
4 に答える
13
UIViews
という名前のプロパティがありますmask
。
mask
常にそれを所有するUIViewの上にあります。
したがって、アプローチは次のようになります。
(これはSwift用ですが、Obj-cに簡単に変換できます)
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
アップデート
- Swift 2の参照は関連性がなくなったため、削除しました。好奇心と同じように、プロパティは呼び出されました
maskView
于 2016-05-12T22:27:26.250 に答える
8
最初は透明で背景色が黒のUIViewを親ビューに追加します。暗くする必要がある場合は、ビューのアルファを0.5に変更します。これは50%透明になります。
于 2011-08-08T18:51:27.500 に答える
3
私は白い背景のビューに行きます:
whiteView=[[UIView alloc]initWithFrame:viewToDim.frame];
[whiteView setBackgroundColor:[UIColor whiteColor]];
[whiteView setAlpha:0.5f];
[self.view insertSubview:whiteView aboveSubview:viewToDim];
于 2014-06-24T21:04:46.960 に答える
0
class UIDecorator: NSObject {
static let sharedInstance = UIDecorator()
private let dimView = UIView()
private let loadingView = MOOverWatchLoadingView(frame: CGRectMake(0, 0, 100, 100),
autoStartAnimation: true)
func showLoadingView() {
if let currentPage = UIApplication.topViewController(){
dimView.frame = currentPage.view.frame
dimView.backgroundColor = UIColor.blackColor()
dimView.alpha = 0.5
currentPage.view.addSubview(dimView)
currentPage.view.userInteractionEnabled = false
loadingView.center = currentPage.view.center
loadingView.backgroundColor = UIColor.clearColor()
currentPage.view.addSubview(loadingView)
}
}
func dismissLocadingView() {
if let currentPage = UIApplication.topViewController(){
currentPage.view.userInteractionEnabled = true
dimView.removeFromSuperview()
loadingView.removeFromSuperview()
}
}
}
于 2017-01-20T20:17:19.150 に答える