苹果设计了一个虚拟旋钮。
How Apple designs a virtual knob (2012)

原始链接: https://jherrm.github.io/knobs/

## GarageBand 令人惊讶的精巧虚拟旋钮 受苹果公司2011年发布的iPad版GarageBand启发,本文深入探讨其虚拟旋钮背后令人惊讶的复杂设计——这是多点触控界面如何提供独特用户体验的一个关键例子。作者发现这些旋钮不仅仅是简单拖动,它们对三种不同的交互方式做出响应:旋转、垂直滑动和水平滑动,从而提供多功能性和精确性。 为了复制这种功能,作者创建了“Knob.js”,一个JavaScript实现。调查GarageBand的代码揭示了多种实现技术。一些旋钮使用放置或旋转的指示器覆盖静态背景(使用CSS、SVG或canvas创建),而另一些则使用通过以小增量旋转基本图像生成的重复背景图像。值得注意的是,许多旋钮利用一系列图像——最多120个——来模拟3D旋钮的旋转。 这种对细节的关注,包括在应用程序文件中发现的未使用的旋钮设计,突显了苹果公司致力于创造直观且“恰到好处”的用户体验,即使是在看似简单的控件中。作者强调这些微妙的设计选择如何促成苹果产品的整体精良和成功。 你可以在[github.com/jherrm/knobs](github.com/jherrm/knobs)找到代码和演示。

## 苹果虚拟旋钮设计:深度解析 (2012) 一篇2012年的文章,详细介绍了苹果在GarageBand等应用中虚拟旋钮的设计,在Hacker News上引发了讨论。核心观点是苹果对细节的关注,即使是在看似简单的UI元素上。用户发现这些旋钮提供了*三种*交互方式:标准旋转、水平滑动和垂直滑动——这一特性并不显而易见。 讨论迅速转向这种复杂性是否是好的设计。一些人赞扬苹果努力创造一个多功能的控制,尤其是在需要多次旋转的任务中,而另一些人则认为其不直观的性质损害了可用性。一个反复出现的主题是拟物化与高效触摸屏交互之间的张力。 许多评论者强调了旋钮在DAW(数字音频工作站)中的普遍性,这归因于空间限制和对精确控制的需求。滑块和数字输入等替代方案被讨论,各自都有清晰度、精度和屏幕空间等方面的论点。最终,这次对话展示了将物理交互翻译成数字界面所面临的细微挑战,以及用户体验设计背后的不同理念。原文作者也参与了讨论,为设计选择辩护,尽管承认最初存在困惑。
相关文章

原文

💡 Author's note: This unpublished post was originally written in May 2012, and refreshed for publication in November 2022.

Just want to see the code? Check out github.com/jherrm/knobs

When Apple introduced Garageband for the iPad back in March 2011, I just had to try it out. It wasn’t just the ability to create music that drew me in, it was the realization that this was a flagship app that uses the strengths of a multitouch interface to create experiences that weren’t possible with a keyboard and mouse. My favorite example is how you can hit a note on the sound sampler keyboard then drag your fingers left and right to bend the pitch.

Some time after a new type of interface is introduced, a handful of concepts tend to “win” and become a standard way of interacting with the interface. Keyboard shortcuts and right click contextual menus aren’t tied to a specific OS, they’re part of the standard toolset you get by using a keyboard and mouse. The iPhone popularized pinch-to-zoom, swipe, long tap, and many other useful multitouch interactions. With Garageband, Apple explored uncharted waters in user interaction and I’m going to talk about one simple control that has a few surprises in both use and implementation: the virtual knob.

Apple’s Three Ways to Turn a Virtual Knob

After using the knobs in Garageband for a while, I noticed that they didn’t always react the way I thought they would. Most of the time the little indicator dot on the knob would follow my finger as I spun the knob around in a circle. Other times the knob wouldn’t follow my finger at all and seemed to go in random directions. I eventually figured out that I had stumbled on three different ways to turn a virtual knob. I was so impressed by this added functionality that I had to try and reproduce it myself, which led to me writing Knob.js, a javascript implementation of multitouch knobs that attempt to replicate the knobs found in Garageband. Knob.js powers all of the examples used in this post.

Spin

The natural interaction with a knob is to spin, so being able to touch the knob and drag it in a circle is key to a successful virtual knob. You can start the spin at any point on the knob, and if your finger is hiding the indicator you can drag away from the knob as you spin, so you can see what’s going on. Dragging further away from the center of the knob also lets you be more precise in setting the value.

Vertical Slide

Just as pinch-to-zoom actually wraps zoom, pan and rotate in one gesture, Apple’s knobs also do double duty as sliders. By sliding your finger in a vertical line, the knob will lock into vertical slider mode. This makes it super easy to make the knob spin several full revolutions without giving your finger a workout. Just like a real life physical knob, the direction the knob spins is dependent on which side of the knob you turn. If you start sliding down on the right side of the knob, it will spin clockwise, and if you start sliding down on the left side of the knob it turns counter-clockwise. (spin disabled)

Another bonus of using the vertical slide gesture with multitouch is you can easily change multiple knobs with one gesture on one hand. Using one finger per knob, drag straight up or down as if they were sliders on a audio mixing board.

Horizontal Slide

Like the vertical slide, if you start sliding in a horizontal line the knob will lock into horizontal slider mode. Start sliding at the top and moving right causes the knob to spin clockwise, and starting at the bottom and going right will spin the knob counter-clockwise. (spin and vertical slide disabled)

All Together Now

The demos above restrict the functionality to show each type of interaction one at a time. Try all three interactions together, as well as mouse/trackpad scrolling support on this button:

How Were They Built?

When I set out to replicate the knobs in Garageband, the first thing I did was open up the Garageband.ipa file and extract the assets. What I found was that in order to recreate the classic knobs from various instruments and amps, the developers used several techniques to bring the knobs to life in an efficient and realistic way.

Knobs with static backgrounds

Below we have a knob made with two images: a non-moving knob “background” and an indicator. The indicator is simply repositioned to create the turning effect. In Garageband, the generic and clavinet knobs all use this technique.

Here’s another knob with a non-moving background, but instead of positioning the indicator to simulate turning, it rotates the indicator instead. Another neat thing about this knob is it, along with the knobs shown at the beginning of this post, are created with CSS rather than images. You can also render a knob with SVG and canvas. The pad and panner knobs in Garageband uses the rotating indicator method, though panner looks like a simple repositioned indicator knob.

A third variation of a knob with a non-moving background is found by combining the other two indicator transformations. An indicator that’s both positioned and rotated offers a nice way to emulate real knobs. The rhodes electric piano knobs in Garageband show off this style.

Knobs with repeating backgrounds

Apple uses repeating backgrounds for knobs that change more than just their indicator as they’re spun around. To make one of these knobs just create the knob image without the indicator, rotate the image a few degrees and save a new image until the pattern is repeated. Combine all of the generated images side by side into one wide grid. Thanks to Google Trimble 3D Warehouse, I was able to find some 3D knobs and recreate the process using blender and photoshop:

Here’s one that I made that has a 13 image repeated progression:

Of course you can also combine a repeating background with the indicator styles. The hammond knobs on the organs in Garageband are an example of a repeating background and a positioned indicator. The knobs on the generic synthesizers show off a repeated background and an indicator that’s rotated and positioned.

Garageband Hammond knob source file with a 5 image repeating sequence.

Garageband Synth knob source file with a 17 image repeating sequence.

Fully Rendered 3D Knobs

Some knobs just can’t be reproduced with static images or repeating backgrounds. Instead of embedding an OpenGL 3D model of the knob, Apple chose to use a similar solution to the repeating background knobs. They basically created a 3D model of then knob then took a picture of it as they spun it around 3 degrees at a time. Since a circle has 360 degrees that means they’re creating 120 different snapshots of the knob! They line them up in order and save it off as a single image that looks like this:

Out of the 25 knobs in Garageband that are able to be turned in all directions, 18 were created using this method.

Thanks to WebGL we could even do one better and use an actual 3D knob! Unfortunately that will have to wait for another day!


Garageband Secrets

While going through the assets extracted from the Garageband, I ended up finding some knobs that didn’t make the cut for inclusion in the final release. I’m happy to breathe some life into these knobs for the first time outside of Apple labs.

Test Knob

Before Apple settled on one image for every 3 degrees for 3D knobs, they tested out one image for every 5 degrees - 72 sprites in all. I can only assume they thought the jump from frame to frame was too jarring and was worth the increase in file size.

Knob Rejects

There were also three knobs that were fully finished but not included. Two were simple color/material changes to existing knobs, but the round arrow knob is new. I especially enjoy the specular highlights that appear on the rounded part of the arrow as you spin it.

Conclusion

Apple’s attention to detail is what has propelled it to be the most valuable company on earth. Whether it’s the click of a physical button or the math behind inertial scrolling, Apple employees work really hard to make products that are deceptively simple and just feel right. The virtual knobs found in Garageband are no exception and I hope others enjoyed learning about them as much as I have.

联系我们 contact @ memedata.com