- Install Ionic and Cordova
npm install -g ionic cordova
- Create new project
ionic start gestures https://github.com/thack/angularu-gestures
cd gestures
ionic platform add ios
(Should be automatic on OSX)ionic platform add android
- Run using Ionic View
- Run on emulator or device
- iOS recommended:
ionic emulate ios -l -c
- Live reload and console output.
- Android recommended (Device or Genymotion):
ionic run android -l -c
- Live reload and console output.
ionic run ios
- Can be tricky because of certificate security.
ionic emulate android
- Slow without HAXM and HAXM is buggy on Mac.
- iOS recommended:
- Add scroll=false to ion-content.
- Add div with square class.
- Add ion-pinch directive to div.
<ion-content scroll="false">
<div class="square" ion-pinch></div>
</ion-content>
- Add CSS to style.css:
.square {
width: 184px;
height: 200px;
background: #DDD url('../img/shield.png') 0/100%;
}
- Add code to app.js for onGesture() function.
ionic.onGesture('touch drag transform dragend', function(e) {
e.gesture.srcEvent.preventDefault();
e.gesture.preventDefault();
switch (e.type) {
case 'touch':
last_scale = scale;
last_rotation = rotation;
break;
case 'drag':
posX = e.gesture.deltaX + lastPosX;
posY = e.gesture.deltaY + lastPosY;
break;
case 'transform':
rotation = e.gesture.rotation + last_rotation;
scale = e.gesture.scale * lastScale
break;
case 'dragend':
lastPosX = posX;
lastPosY = posY;
lastScale = scale;
break;
}
var transform =
"translate3d(" + posX + "px," + posY + "px, 0) " +
"scale(" + scale + ")" +
"rotate(" + rotation + "deg) ";
e.target.style.transform = transform;
e.target.style.webkitTransform = transform;
}, $element[0]);
- Run again using emulator, device, or Ionic View.
- Add Crosswalk
ionic browser add crosswalk
- Run again on Android:
ionic run android
- Shield PNG becomes blurry at high zoom.
- Replace PNG with SVG file for resolution independence.