Mobile Safari Advanced Features

If you’re already building web apps, you might wonder why you should bother to build an iPhone native app. The short answer is that you might not need to, but you should still optimize the app for iPhones.

Native-looking chrome

Set these in the head:

// set a custom icon for when a user bookmarks the app to the home screen
<link rel="apple-touch-icon" href="/path/to/icon.png" /> 
// hide the browser chrome
<meta name="apple-mobile-web-app-capable" content="yes" /> 
//set the phone status bar style; can be grey, black, or black translucent
<meta name="apple-mobile-web-app-status-bar-style" content="black" />

Caveats:

  • Only works for web pages that have been saved to the home screen and opened from there.
  • Portrait mode only.
  • Any link will open in new browser tab. Use ajax to keep application to single page, see dashcode templates for examples.

Query this state via js:

window.navigator.standalone

Detect orientation:

<body onorientationchange="updateOrientation();">

Touchable

Touch Events
They’re different from mouse events, so we’ve gotta code differently for them. The sequence works like this:
touchstart -> touchmove -> touchend (or, if a user hits home button touchcancel)

<div ongtouchstart="function();" >

What you get when from that:

event.touches //all
event.targetTouches //this one
event.changedTouches //um...

Touch events track every finger on the screen. Gestures are a higher-level interface to that data.

<div ongesturestart="function();" >

Scale and rotation properties of that gesture are available. I’m not sure if other gestures, such as page flicking, are handled as gestures or touches.

Visually sophisticated

Apple decided that HTML was seriously deficient in the areas of object transformations, transitions, and keyframe animations.

Why render multiple rotated and resized versions of the images you use throughout your app/web page? Loading a single large version of the image may perform better than having to load multiple versions of the image at various sizes, rotations, or skews.

Here are a few options (see previous):

.transformed {
	-webkit-transform: rotate(20deg);
	-webkit-transform-origin: top left;
}

And it can animate transitions between these styles. Specify the transition duration if you like.

#myFlower {
	-webkit-transform: rotate(0deg);
	-webkit-transform: scale(1.0);
	-webkit-transition-duration: 2s;
}
document.getElementById('myFlower').style.webkitTransform = 'rotate(360dev) scale(0.5)'

Other useful properties that you can set:

-webkit-transition-timing-function
-webkit-transition-delay

It gets a lot more exciting with key framed animation. First, define one or more animations:

@-webkit-keyframes 'fall' {
	from{ -webkit-transform: translateY(-50px); }
	to{ -webkit-transform: translateY(600px); }
}
@-webkit-keyframes 'fade' {
	0% { opacity: 100%; }
	75% { opacity: 100%; }
	100% { opacity: 100%; }
}

Then apply those animations to an object or class:

.leaf {
	-webkit-animation-name: 'fall', 'fade';
	-webkit-animation-duration: 10s, 10s;
	-webkit-animation-iteration-count: infinite, infinite;
	-webkit-animation-timing-function: linear, ease-in;
}

Responsive

Mobile safari supports local database storage as defined in HTML5. Using it improves responsiveness and battery performance.

 

User contributed tags for this post:

window.navigator.standalone (143) - apple-mobile-web-app-capable (70) - apple-mobile-web-app-status-bar-style (41) - iPhone safari gestures (26) - mobile safari hide address bar (24) - mobile safari database (20) - mobile safari databases (20) - mobile safari events (19) - iphone safari hide address bar (17) - mobile safari rss (16) - mobile safari gestures (14) - mobile safari touch events (14) - window.navigator.standalone iphone (12) - mobile safari html (12) - mobile safari features (12) - mobile safari forms (12) - mobile safari html 5 (11) - mobile safari html5 (11) - iPhone safari hide toolbar (11) - mobile safari animation (10) -  (10) - iphone safari hide status bar (10) - mobile safari hide toolbar (10) - mobile safari local storage (10) - mobile safari meta (9) - hide mobile safari address bar (9) - private browsing mobile safari (9) - mobile safari (8) - safari mobile databases (7) - safari page transitions (7) - hide safari address bar iphone (7) - mobile safari rotation (7) - mobile safari localstorage (7) - iPhone Safari page transitions (7) - mobilesafari databases (6) - iphone hide safari chrome (6) - Mobile Safari Animations (6) - safari mobile rss (6) - safari mobile features (6) - safari mobile events (6) - mobile safari meta tags (6) - mobile safari private browsing (6) - iphone address bar hide (6) - mobile (5) - safari mobile (5) - webkitTransform iphone (5) - webkit gestures (5) - iphone safari hide bar (5) - safari gesture (5) - iphone safari no rotate (5) - safari transitions (5) - hide address bar mobile safari (5) - dashcode gestures (5) - safari local database (5) - mobile safari touchstart (5) - safari mobile database (5) - iphone window.navigator.standalone (5) - mobile safari transitions (5) - iphone webapp rotation (5) - mobile safari status bar (5) - iphone hide status bar safari (5) - mobile Safari hide bar (5) - mobile safari storage (4) - apple-mobile-web-app-capable onorientationchange (4) - mobile safari open link in new window (4) - iphone safari open local file (4) - Ipod safari gestures (4) - apple-mobile-web-app-capable links (4) - Hide iPhone safari status bar (4) - iphone safari gesture (4) - mobile safari 3 (4) - dashcode mobile safari (4) - safari mobile hide address bar (4) - hide mobile safari toolbar (4) - iphone mobile safari hide toolbar (4) - mobile safari ajax (4) - apple-mobile-web-app-capable orientation (4) - iphone safari transition (4) - iphone hide safari toolbar (4) - iphone safari transitions (4) - mobile safari page transitions (4) - mobile safari scaling (4) - hide safari toolbar iphone (4) - iphone safari detect rotation (4) - safari page transition (4) - mobile safari hide status bar (4) - webkit-transform iphone (3) - apple-mobile-web-app-status-bar-style black (3) - mobile safari no chrome (3) - mobile safari open in new window (3) - mobile safari hide chrome (3) -  (3) - style.webkitTransform (3) - safari mobile hide status bar (3) - mobile safari gesture (3) - hide chrome in mobile safari (3) - safari mobile store form data (3) - mobile safari hide browser bar (3) - iphone hide browser bar (3) - (3) - translateY iphone (3) - mobile safari icon (3) - mobile safari hide address (3) - Iphone Safari rotation event (3) - Mobile Safari orientation (3) - webkit hide status bar (3) - Mobile Safari gesture events (3) - webkitTransform scale (3) - safari scale transitions (3) - safari mobile gestures (3) - mobile safari hide URL bar (3) - mobile safari rotation event (3) - dashcode hide Address bar (3) - mobile safari open local file (3) - mobile safari html 5 support (3) - dashcode hide url bar (3) - Dashcode iphone samples (3) - open link in new page mobile safari (3) - html database mobile safari (3) - iphone safari scale (3) - iPhone browser hide toolbar (3) - iphone safari hide url bar (3) - ipod safari hide top address bar (3) - mobile safari hide location bar (3) - hide urlbar mobilesafari (3) - hide toolbar iphone safari (3) - keyframe animation button safari (3) - dashcode iphone webapp hide address bar (3) - iphone mobile safari open local files (3) - mobile safari image scaling (3) - ipod safari hide address bar (3) - hide status bar iphone safari (3) - iPHONE style page transitions and webkit (3) - iphone web app page transition (3) - html iphone hide bar (3) - hide address bar iphone safari (3) - mobile safari remove address bar (3) - hide toolbar mobile safari (3) - iphone safari hide url (3) - how to hide the address bar in mobilesafari (3) - hide mobile webkit browser chrome (3) - iphone safari remove address bar (3) - iphone hide address bar safari (3) - hide mobile safari chrome (3) - hide address bar in mobile safari (3) - mobile safari Hide the URL address bar after the page loads (3) - iphone hide safari status bar (3) - mobilesafari database (3) - apple mobile web app capable links opening in safari (3) - webkit hide address bar (3) -