Jerome's implementation brings up a point about UX that may interest
some of you. Across nearly all iPhone apps, a user can tap on the
clock at any time to scroll to the top of the current page or list (in
Safari, it scrolls up AND displays the address bar). You probably
don't want to break this expected behavior. In particular it's very
common to use this method in Safari to enter a new URL or to use the
search box.
Assigned setInterval a time of 2 seconds means that every two seconds,
the address bar will slide out of view. IMO, this isn't a user-
friendly amount of time to retain the tap-the-clock feature in Safari.
I've upped it to 5 seconds in my code.
I can think of two use cases for a user tapping on the clock: 1) they
want to enter a URL or search, and 2) it was an accident (or they
changed their mind and want to stay on your page).
Case 1:
Tapping the clock gives the user a few seconds* to then tap either the
URL input or the search input. Once either of these has focus, the
setInterval is effectively 'paused' -- the address bar will remain in
view until the user taps back on the web page. At that point,
setInterval is 'unpaused', and after a few seconds the address bar
will disappear and the web page will resume being "full screen".
Case 2:
If the user taps the clock and then does NOT tap either the URL input
or search box, the address bar will quietly slip away after a few
seconds. This is useful for maintaining the "full screen" look when
accidental or unwanted taps on the clock occur.
I think an interval of 5 or 6 seconds is the best way to accommodate
both use cases. Thoughts?
* When I say "a few seconds", it could really be anywhere from 0-5
seconds, with an average of (obviously) 2.5 seconds. In some cases
this will be too short (appearing to respond hostily to the user's
action) or too long (appearing to be unresponsive or broken). However
I think it's a decent compromise, especially if you expect users to
use your app more than once (in which case they'll understand from
past experience that they just need to try again or wait).
Obviously the ideal solution to all of this would be the pseudo-code
below, but if it were possible then this thread wouldn't exist :)
setInterval(checkAddressBarVisibility,500);
function checkAddressBarVisibility()
{
if (address bar is open) {
setTimeout(closeAddressBar,1500);
// Remember that this would only run if neither the URL input nor
search box had focus
// i.e., it would only run when the user was not interested in using
the address bar