23.01.2018 Views

MICROSOFT_PRESS_EBOOK_PROGRAMMING_WINDOWS_8_APPS_WITH_HTML_CSS_AND_JAVASCRIPT_PDF

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Now I’m sure you’re asking some important questions. While I’ve been speaking of pinch-stretch,<br />

rotation, and translation gestures as different things, how does one, in fact, differentiate these gestures<br />

when they’re all coming into the app through the same MSGestureChange event? Doesn’t that just make<br />

everything confusing? What’s the strategy for translation, rotation, and scaling gestures?<br />

Well, the answer is—you don’t have to separate them! If you think about it for a moment, how you<br />

handle MSGestureChange events and the data each one contains depends on the kinds of manipulations<br />

you actually support in your UI:<br />

• If you’re supporting only translation of an element, you’ll simply never pay any attention to<br />

properties like scale and rotation and apply only those like translationX and translationY.<br />

This would be the expected behavior for selecting an item in a collection control, for example (or<br />

a control that allowed drag-and-drop of items to rearrange them).<br />

• If you support only zooming, you’ll ignore all the positional properties and work with scale,<br />

expansion, and/or velocityExpansion. This would be the sort of behavior you’d expect for a<br />

control that supported optical or semantic zoom.<br />

• If you’re interested in only rotation, the rotation and velocityAngular properties are your<br />

friends.<br />

Of course, if you want to support multiple kinds of manipulations, you can simply apply all of these<br />

properties together, feeding them into <strong>CSS</strong> transforms, for instance. This would be expected of an app<br />

that allowed arbitrary manipulation of on-screen objects, and it’s exactly what one of the gesture<br />

samples of the Windows SDK demonstrates.<br />

The Input Instantiable Gesture Sample<br />

While the PointerEvents example included with this chapter gives us a raw view of pointer and gesture<br />

events, what really matters to apps is how to apply these events to real manipulation of on-screen<br />

objects, which is to say, implementing parts of touch language such as pinch/stretch and rotation. For<br />

these we can turn to the Input Instantiable gestures sample.<br />

This sample primarily demonstrates how to use gesture events on multiple elements simultaneously.<br />

In Scenarios 1 and 2, the app simulates a simple example of a puzzle app, as mentioned earlier. Each<br />

colored box can be manipulated separately, using drag to move (with or without inertia), pinch-stretch<br />

gestures to zoom, and rotation gestures to rotate, as shown in Figure 9-4.<br />

384

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!