音量与设置音量

发布于 2024-12-19 13:21:48 字数 317 浏览 1 评论 0原文

我正在查看开发人员文档,发现两种方法似乎做同样的事情,但我无法区分它们之间的区别。

例如,在 NSSound 中:

[mySound volume];

[mySound setVolume:0.2];

这两段代码的结果会是什么

我知道后者将音量设置为我想要的值。我将其设置为0.2;如果我走得更高,音量显然会增加,但是第一个例子呢?

它有什么作用,我将在哪里单独使用它们,为什么?

I was looking through the developer documentation and found two methods which seem to do the same thing, but I couldn't tell the difference between them.

For example in NSSound:

[mySound volume];

and

[mySound setVolume:0.2];

what would be the outcome of these two pieces of code?

I know that the latter sets the volume to what I want it to. I set it to 0.2; if I go higher, the volume is increased, obviously, but what about the first example?

What does that do, where I would use these separately, and why?

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

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

发布评论

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

评论(2

玩物 2024-12-26 13:21:48

在本例中,“音量”是 mySound 对象的属性。你是对的,在第二个示例中,你将该属性设置为 0.2。第一个示例是该属性的 getter。它将返回当前的音量值给您。例如,如果您这样做:

[mySound setVolume:0.2];
float newVolume = [mySound volume];

newVolume 中的值将为 0.2。

In this case 'volume' is a property of the mySound object. You are right, in the second example you are setting that property to 0.2. The first example is the getter for that property. It will return the current value of volume to you. For example if you did this:

[mySound setVolume:0.2];
float newVolume = [mySound volume];

The value in newVolume would be 0.2.

寒江雪… 2024-12-26 13:21:48

它是一个所谓的“getter”,返回 mySoundvolume 的当前值。通常,您可以通过将返回值分配给变量来调用它:

float currentVolume = [mySound volume];

It is a so called "getter" and returns the current value of mySound's volume. You would typically call it by assigning the return value to a variable:

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