更改窗口背景的 Alpha,而不是整个窗口
所以我有一个简单的问题,我有下面的方法,它根据滑块的值设置窗口的 alpha 值,但是窗口的内容也会变得半透明,并最终随窗口一起消失。
有没有办法只更改窗口的 alpha 值而不更改其中的内容视图?
- (IBAction)changeTransparency:(id)sender {
// Set the window's alpha value. This will cause the views in the window to redraw.
[self.window setAlphaValue:[sender floatValue]];}
谢谢,萨米。
so i have a quick question i have the method below which sets the alpha value of a window depending on the value from a slider, however the content of the window also becomes translucent and eventually disappears with the window.
Is there a way to just change the alpha value of the window and not the content view inside it?
- (IBAction)changeTransparency:(id)sender {
// Set the window's alpha value. This will cause the views in the window to redraw.
[self.window setAlphaValue:[sender floatValue]];}
Thanks, Sami.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Apple 的文档给出了一种方法来做到这一点。关键是将窗口的
backgroundColor
的 alpha 设置为所需的值。您还必须确保将窗口的opaque
属性设置为NO
(默认情况下为YES
)。
Apple's docs gives a way to do this. The key is to set the window's
backgroundColor
's alpha to the desired value. You must also make sure to set the window'sopaque
property toNO
(which isYES
by default.)e.x.
这是另一种方法。
认为,
self.window <--- 基本视图并且这个 alpha 将被更改(但完全是假的)。
subView1, subView2 <-- 这些视图是 self.window 的内容。并且不应更改其 alpha 值。
您可以使用上面的代码创建一个方法:)
Here is another way.
Suppose,
self.window <--- base view and this alpha will be changed (but exacatly fake).
subView1, subView2 <-- these views are contents of self.window. and theier alpha should not be changed.
You can make a method using above code :)