您之前可能已经见过这种情况,它在像 ScoutMob 这样的时尚消费应用程序中变得非常流行。我正在尝试在启动时实现一个 60% 的透明 View ,它将覆盖我的主屏幕,解释如何使用主屏幕的功能并在点击时消失。
我已经完成了我的整个应用程序(它从几年前就开始使用 .xib,但也可以随意以 Storyboard格式进行解释,因为我可能会在其他 iOs 5.0+ 应用程序中重用此功能。)
我制作单个 View 没问题,但临时将一个 View 叠加在另一个 View 之上是我一直没有想到的事情。我将继续研究并包括我发现的任何有用的提示,以防其他人试图做同样的事情。
最佳答案
// get your window screen size
CGRect screenRect = [[UIScreen mainScreen] bounds];
//create a new view with the same size
UIView* coverView = [[UIView alloc] initWithFrame:screenRect];
// change the background color to black and the opacity to 0.6
coverView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.6];
// add this new view to your main view
[self.view addSubview:coverView];
完成后,您可以将其删除:
[coverView removeFromSuperview];
Swift3 版本:
// get your window screen size
let screenRect = UIScreen.main.bounds
//create a new view with the same size
let coverView = UIView(frame: screenRect)
// change the background color to black and the opacity to 0.6
coverView.backgroundColor = UIColor.black.withAlphaComponent(0.6)
// add this new view to your main view
self.view.addSubview(coverView)
删除它:
coverView.removeFromSuperview()
关于ios - 如何在当前 View 上方制作半透明 View 层?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16283324/