Return to site

Multi Touch Apple

broken image


Introduction

Mobile devices such as smartphones and tablets usually have a capacitivetouch-sensitive screen to capture interactions made with the user's fingers. Asthe mobile web evolves to enable increasingly sophisticated applications, webdevelopers need a way to handle these events. For example, nearly anyfast-paced game requires the player to press multiple buttons at once, which,in the context of a touchscreen, implies multi-touch.

The 2012 iPhone 5 replaced the previous touch screen with an in-cell touch screen that still uses capacitive multi-touch technology, but combines the capacitive touch.

Apple CEO Steve Jobs shows off the MacBook's new glass trackpad, which, like the iPhone, understands multifinger gestures. For good reason too. Apple didn't invent multitouch, here's a demo from Jeff Han from 2006 where he demos multitouch: It was invalidated, yes, but not for the reasons you suggest. Find helpful customer reviews and review ratings for Apple iPad Pro 12.9-Inch With Multi-Touch Retina Display (32GB, WiFi Only, Space Gray, 2732 x 2048 Resolution) at Amazon.com. Read honest and unbiased product reviews from our users. The Magic Mouse is a multi-touch mouse produced by Apple Inc. It can be used as a single-touch or multi-touch device in Ubuntu by pairing it using the Bluetooth utilities in Ubuntu. The following setup instructions only need to be followed once, then Ubuntu will recognize the Magic Mouse without further configuration.

Apple introduced their touchevents API in iOS 2.0. Android has been catching up to this de-factostandard and closing the gap. Recently a W3C working group has come together towork on this touchevents specification.

In this article I'll dive into the touch events API provided by iOS andAndroid devices, as well as desktop Chrome on hardware that supports touch, and explore what sorts of applications you can build, present somebest practices, and cover useful techniques that make it easier to developtouch-enabled applications.

Touch events

Three basic touch events are outlined in the spec and implementedwidely across mobile devices:

  • touchstart: a finger is placed on a DOM element.
  • touchmove: a finger is dragged along a DOM element.
  • touchend: a finger is removed from a DOM element.

Each touch event includes three lists of touches:

  • touches: a list of all fingers currently on the screen.
  • targetTouches: a list of fingers on the current DOMelement.
  • changedTouches: a list of fingers involved in the currentevent. For example, in a touchend event, this will be the finger that was removed.
These lists consist of objects that contain touch information:
  • identifier: a number that uniquely identifies the current finger in thetouch session.
  • target: the DOM element that was the target of theaction.
  • client/page/screen coordinates: where on the screen the actionhappened.
  • radius coordinates and rotationAngle: describe the ellipsethat approximates finger shape.
Apple

Touch-enabled apps

The touchstart, touchmove, andtouchend events provide a rich enough feature set to supportvirtually any kind of touch-based interaction – including all of the usualmulti-touch gestures like pinch-zoom, rotation, and so on.

This snippet lets you drag a DOM element around using single-fingertouch:

Below is a samplethat displays all current touches on the screen. It's useful just to get afeeling for the responsiveness of the device.

Demos

A number of interesting multi-touch demos are already in the wild, suchas this canvas-based drawing demoby Paul Irish and others.

And Browser Ninja, a techdemo that is a Fruit Ninja clone using CSS3 transforms and transitions, as well ascanvas:

Best practices

Prevent zooming

Default settings don't work very well for multi-touch, since your swipes andgestures are often associated with browser behavior, such as scrolling andzooming.

To disable zooming, setup your viewport so that it is not user scalable usingthe following meta tag:

Check out this mobile HTML5 article for more information on setting your viewport.

Prevent scrolling

Some mobile devices have default behaviors for touchmove, such as theclassic iOS overscroll effect, which causes the view to bounce back whenscrolling exceeds the bounds of the content. This is confusing in manymulti-touch applications, and can easily be disabled:

Render carefully

If you are writing a multi-touch application that involves complexmulti-finger gestures, be careful how you react to touch events, since you willbe handling so many at once. Consider the sample in the previous section thatdraws all touches on the screen. You could draw as soon as there is a touchinput:

But this technique does not scale with number of fingers on the screen. Instead, you could track all of the fingers, and render in a loop to get farbetter performance:

Tip: Core temp. setInterval is not great for animations, since it doesn't take intoaccount the browser's own rendering loop. Modern desktop browsers provide requestAnimationFrame,which is a much better option for performance and battery life reasons. Oncesupported in mobile browsers, this will be the preferred way of doingthings.

Make use of targetTouches and changedTouches

Remember that event.touches is an array of ALLfingers in contact with the screen, not just the ones on the DOM element'starget. You might find it much more useful to use event.targetTouches orevent.changedTouches instead.

Finally, since you are developing for mobile, you should be aware of general mobile best practices, which are covered in Eric Bidelman's article, as well as this W3C document.

Device support

Unfortunately, touch event implementations vary greatly in completeness andquality. I wrote a diagnostics script that displays some basic information about the touch APIimplementation, including which events are supported, and touchmove firingresolution. I tested Android 2.3.3 on Nexus One and Nexus S hardware, Android3.0.1 on Xoom, and iOS 4.2 on iPad and iPhone.

In a nutshell, all tested browsers support the touchstart, touchend, and touchmove Downcast 2 9 16 download free. events.

The spec provides three additional touch events, but no tested browserssupport them:

  • touchenter: a moving finger enters a DOM element.
  • touchleave: a moving finger leaves a DOM element.
  • touchcancel: a touch is interrupted (implementationspecific).

Within each touch list, the tested browsers also provide thetouches, targetTouches andchangedTouches touch lists. However, no tested browserssupport radiusX, radiusY or rotationAngle, which specify the shape of the finger touching the screen.

During a touchmove, events fire at roughly 60 times a second across alltested devices.

Android 2.3.3 (Nexus)

On the Android Gingerbread Browser (tested on Nexus One and Nexus S), thereis no multi-touch support. This is a known issue.

Android 3.0.1 (Xoom)

On Xoom's browser, there is basic multi-touch support, but it only works ona single DOM element. The browser does not correctly respond to twosimultaneous touches on different DOM elements. In other words, the followingwill react to two simultaneous touches:

Multi Touch Apple

Touch-enabled apps

The touchstart, touchmove, andtouchend events provide a rich enough feature set to supportvirtually any kind of touch-based interaction – including all of the usualmulti-touch gestures like pinch-zoom, rotation, and so on.

This snippet lets you drag a DOM element around using single-fingertouch:

Below is a samplethat displays all current touches on the screen. It's useful just to get afeeling for the responsiveness of the device.

Demos

A number of interesting multi-touch demos are already in the wild, suchas this canvas-based drawing demoby Paul Irish and others.

And Browser Ninja, a techdemo that is a Fruit Ninja clone using CSS3 transforms and transitions, as well ascanvas:

Best practices

Prevent zooming

Default settings don't work very well for multi-touch, since your swipes andgestures are often associated with browser behavior, such as scrolling andzooming.

To disable zooming, setup your viewport so that it is not user scalable usingthe following meta tag:

Check out this mobile HTML5 article for more information on setting your viewport.

Prevent scrolling

Some mobile devices have default behaviors for touchmove, such as theclassic iOS overscroll effect, which causes the view to bounce back whenscrolling exceeds the bounds of the content. This is confusing in manymulti-touch applications, and can easily be disabled:

Render carefully

If you are writing a multi-touch application that involves complexmulti-finger gestures, be careful how you react to touch events, since you willbe handling so many at once. Consider the sample in the previous section thatdraws all touches on the screen. You could draw as soon as there is a touchinput:

But this technique does not scale with number of fingers on the screen. Instead, you could track all of the fingers, and render in a loop to get farbetter performance:

Tip: Core temp. setInterval is not great for animations, since it doesn't take intoaccount the browser's own rendering loop. Modern desktop browsers provide requestAnimationFrame,which is a much better option for performance and battery life reasons. Oncesupported in mobile browsers, this will be the preferred way of doingthings.

Make use of targetTouches and changedTouches

Remember that event.touches is an array of ALLfingers in contact with the screen, not just the ones on the DOM element'starget. You might find it much more useful to use event.targetTouches orevent.changedTouches instead.

Finally, since you are developing for mobile, you should be aware of general mobile best practices, which are covered in Eric Bidelman's article, as well as this W3C document.

Device support

Unfortunately, touch event implementations vary greatly in completeness andquality. I wrote a diagnostics script that displays some basic information about the touch APIimplementation, including which events are supported, and touchmove firingresolution. I tested Android 2.3.3 on Nexus One and Nexus S hardware, Android3.0.1 on Xoom, and iOS 4.2 on iPad and iPhone.

In a nutshell, all tested browsers support the touchstart, touchend, and touchmove Downcast 2 9 16 download free. events.

The spec provides three additional touch events, but no tested browserssupport them:

  • touchenter: a moving finger enters a DOM element.
  • touchleave: a moving finger leaves a DOM element.
  • touchcancel: a touch is interrupted (implementationspecific).

Within each touch list, the tested browsers also provide thetouches, targetTouches andchangedTouches touch lists. However, no tested browserssupport radiusX, radiusY or rotationAngle, which specify the shape of the finger touching the screen.

During a touchmove, events fire at roughly 60 times a second across alltested devices.

Android 2.3.3 (Nexus)

On the Android Gingerbread Browser (tested on Nexus One and Nexus S), thereis no multi-touch support. This is a known issue.

Android 3.0.1 (Xoom)

On Xoom's browser, there is basic multi-touch support, but it only works ona single DOM element. The browser does not correctly respond to twosimultaneous touches on different DOM elements. In other words, the followingwill react to two simultaneous touches:

But the following will not:

iOS 4.x (iPad, iPhone)

iOS devices fully support multi-touch, are capable of tracking quite a fewfingers and provide a very responsive touch experience in the browser.

Developer tools

In mobile development, it's often easier to start prototyping on the desktopand then tackle the mobile-specific parts on the devices you intend to support.Multi-touch is one of those features that's difficult to test on the PC, sincemost PCs don't have touch input.

Having to test on mobile can lengthen your development cycle, since everychange you make needs to be pushed out to a server and then loaded on thedevice. Then, once running, there's little you can do to debug yourapplication, since tablets and smartphones lack web developer tooling.

A solution to this problem is to simulate touch events on your developmentmachine. For single-touches, touch events can be simulated based on mouseevents. Multi-touch events can be simulated if you have a device with touchinput, such as a modern Apple MacBook.

Single-touch events

If you would like to simulate single-touch events on your desktop, Chrome provides touch event emulation from the developer tools. Open up the Developer tools, then select the Settings gear, then 'Overrides' or 'Emulation', and turn on 'Emulate touch events'.

For other browsers, you may wish to try outPhantom Limb, which simulates touch events on pages and also gives a giant hand to boot.

Apple Multi Touch Device Manager

There's also the TouchablejQuery plugin that unifies touch and mouse events across platforms.

Multi-touch events

To enable your multi-touch web application to work in your browser on yourmulti-touch trackpad (such as a Apple MacBook or MagicPad), I've created the MagicTouch.js polyfill. Itcaptures touch events from your trackpad and turns them intostandard-compatible touch events.

  1. Download and install the npTuioClient NPAPI plugin into~/Library/Internet Plug-Ins/.
  2. Download the TongSeng TUIO app for Mac's MagicPad and startthe server.
  3. Download MagicTouch.js, a javascript library tosimulate spec-compatible touch events based on npTuioClient callbacks.
  4. Include the magictouch.js script and npTuioClient plugin in yourapplication as follows:

You may need to enable the plugin:

A live demo with magictouch.js is available at paulirish.com/demo/multi:

I tested this approach only with Chrome 10, but it should work on othermodern browsers with only minor tweaks.

If your computer does not have multi-touch input, you can simulate touchevents using other TUIO trackers, such as the reacTIVision. Formore information, see the TUIO project page.

Note that your gestures might be identical to OS-level multi-touch gestures.On OS X, you can configure system-wide events by going to the Trackpadpreference pane in System Preferences.

Iphone 6 Plus Touch Issues

As multi-touch features become more widely supported across mobile browsers,I'm very excited to see new web applications take full advantage of this richAPI.





broken image