UIPresentModalViewController 视图 alpha 未设置

发布于 01-07 00:36 字数 903 浏览 6 评论 0原文

我想展示一个视图控制器,其中有一个背景图像视图。 该图像视图的 Alpha 为 0.5(所以想添加为半透明黑色图像)。但是当我呈现该视图控制器时,alpha 不适用于视图。该图像看起来完全是黑色的,就像 Alpha 尚未设置一样。

此问题仅适用于 iPad 设备。

请帮帮我。

Code:
ViewController1.m:
[self presentModalViewController:viewController2];

ViewController2.xib: (in nib I am setting below values no in code)
[self.view setBackgroundColor:[UIColor clearColor]];
[self.bgImageView setAlpha:0.5]; // this image is dark black, i want to display the 

屏幕内容位于此(viewController1.view)后面,有点半透明

我又尝试了一件事,这次我删除了 imageView 并将 uiview bgcolor 设置为黑色,不透明=NO,alpha=0.2(在笔尖本身) 。因此,虽然呈现的动画看起来很完美。但是当视图被放置时,它会变成 alpha=1.0(全黑)

仍然没有透明度,我在这里错在哪里。

答案就在这里ModalViewController存在一些错误/限制,因此在这种情况下最好使用addSubview

I want to present a view controller where I have one Background imageView.
Alpha for that imageview is 0.5 (want to add as semi-transperant black image so). But when I present that view controller that alpha doesn't work for view. That image entirely looks blackish, like alpha has not been even set.

This issue is there for iPad device only.

Please help me out.

Code:
ViewController1.m:
[self presentModalViewController:viewController2];

ViewController2.xib: (in nib I am setting below values no in code)
[self.view setBackgroundColor:[UIColor clearColor]];
[self.bgImageView setAlpha:0.5]; // this image is dark black, i want to display the 

content of the screen which is behind this (viewController1.view), kind of semi-transperancy

I tried one more thing, this time i have removed imageView and set uiview bgcolor to black, opaque=NO, alpha=0.2 (in nib itself). So while animation of presenting it looks perfect. But when view has been placed it turns into alpha=1.0 (complete black)

Still there is no transparency where am i wrong over here.

Answer Is Here: There is some bug/limitation with ModalViewController so its better to go with addSubview for such situation

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浅紫色的梦幻2025-01-14 00:36:27

在呈现 modelviewcontroller 后尝试编写 imageview.alpha = 0.5 并看看会发生什么。尝试一下吧。

编辑:
1)清理构建并运行

您尝试设置的图像alpha,是在您正在呈现的视图控制器中还是在模态视图控制器中?

Try to write imageview.alpha = 0.5 after you present the modelviewcontroller and see what happens. Just give it a try.

EDIT:
1)Clean Build and Run

The image alpha you are trying to set, is it in viewcontroller that you are presenting from or is it in modalviewcontroller?

雨的味道风的声音2025-01-14 00:36:27

答案在这里: ModalViewController 存在一些错误/限制,因此最好对于这种情况,请使用 addSubview

Answer Is Here: There is some bug/limitation with ModalViewController so its better to go with addSubview for such situation

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文