如何在当前视图上方创建半透明视图层? [英] How do I make a semi-transparent view layer above a current view?

查看:121
本文介绍了如何在当前视图上方创建半透明视图层?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

之前你可能已经看到过它,它在像ScoutMob这样的消费时尚应用中变得非常流行。我正试图在启动时实现60%透明视图,覆盖我的主屏幕,解释如何使用主屏幕的功能并在点击时消失。

You've likely seen this before, its become exceedingly popular in consumery chic apps like ScoutMob. I'm trying to implement a 60% transparent view on launch that will cover my home screen, explaining how to use the functions of the home screen and disappears on tap.

我完成了我的整个应用程序(它是从几年前开始使用.xib的,但是也可以用故事板格式来解释,因为我可能会重用这个其他iOs 5.0+应用程序中的功能。)

I have my entire app completed (it's using .xib's since its from a years ago, but feel free to explain in storyboard format as well, since I will likely reuse this feature in other iOs 5.0+ applications.)

我制作单个视图没有问题,但暂时将一个视图叠加在另一个上面是我没有直观地想出来的。我将继续研究并包括我发现的任何有用的提示,以防其他人试图做同样的事情。

I have no problem making single views, but temporarily layering one on top of another is something I haven't figured out intuitively. I'll continue researching and include any helpful tips I find in case other people are trying to do the same thing.

推荐答案

// 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];

完成后,你可以删除它:

when you are done with it , you can remove it :

[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()

这篇关于如何在当前视图上方创建半透明视图层?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆