Kru*_*lur 6 cocoa-touch uiview ios
想法是显示进度对话框.我试图用透明的黑色视图(alpha 0.2)覆盖父视图(通常是整个屏幕).最重要的是,我想显示一个较小的视图,也透明与另一种颜色.它可能不受第一视图的颜色或透明度的影响.在第二个视图中,我想要不透明的UI元素.我已经尝试了一切,甚至在这里找到了处理相似内容的帖子,但只使用了一个透明层.而那些已经使用了奇怪的技巧.有没有一种标准的,简单的方法来实现这一目标?
drawRect:如果您对视图进行分组,则无需任何黑客攻击或复杂且可能会降低自定义速度:
创建包含并保存整个对话框的边界视图.此视图本身没有可见内容,其backgroundColor很清晰.它的alpha是1.0.
现在将所有透明视图(alpha <1)视图添加到您想要的视图中,并添加非透明视图.注意不要将任何非透明视图添加为透明视图的子视图,而是将它们添加为边界视图的直接子视图.这样,他们将继承其1.0的alpha值.
UIView *progressDialogView = [[UIView alloc] initWithFrame:dialogFrame];
progressDialogView.backgroundColor = [UIColor clearColor];
progressDialogView.alpha = 1.0; //you can leave this line out, since this is the default.
UIView *halfTransparentBackgroundView = [[UIView alloc] initWithFrame:dialogFrame];
halfTransparentBackgroundView.backgroundColor = [UIColor blackColor]; //or whatever...
halfTransparentBackgroundView.alpha = 0.5;
[progressDialogView addSubview: halfTransparentBackgroundView];
UIView *progressBarView = [[UIView alloc] initWithFrame:progressBarFrame];
progressBarView.backgroundColor = [UIColor blueColor];
[progressDialogView addSubview: progressBarView];
Run Code Online (Sandbox Code Playgroud)
小智 5
不使用设置alpha属性,而是使用以下内容为每个视图设置背景颜色/不透明度:
view1.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:.3];
Run Code Online (Sandbox Code Playgroud)
使用您想要的红色,绿色,蓝色和alpha值.
我在博客中找到了答案:http://cocoawithlove.com/2009/04/showing-message-over-iphone-keyboard.html
解决方案是覆盖drawRect:并处理其中的 alpha。您不能触摸UIView'salpha 属性,也不能将视图的背景颜色设置为透明以外的任何颜色。所有绘图都必须以这种方式进行,drawRect:.我能够堆叠透明视图并将不透明元素放在顶部。
| 归档时间: |
|
| 查看次数: |
21910 次 |
| 最近记录: |