音量与设置音量
我正在查看开发人员文档,发现两种方法似乎做同样的事情,但我无法区分它们之间的区别。
例如,在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在本例中,“音量”是 mySound 对象的属性。你是对的,在第二个示例中,你将该属性设置为 0.2。第一个示例是该属性的 getter。它将返回当前的音量值给您。例如,如果您这样做:
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:
The value in newVolume would be 0.2.
它是一个所谓的“getter”,返回
mySound
的volume
的当前值。通常,您可以通过将返回值分配给变量来调用它:It is a so called "getter" and returns the current value of
mySound
'svolume
. You would typically call it by assigning the return value to a variable: