Activate your free membership today | Log-in

Tuesday, December 2nd, 2008

S5 Presentations with CSS Transitions

Category: Ajax, CSS, iPhone

Shawn Lauriat hacked CSS Transition support into the presentation app S5. Now he has posted slides from one of his talks that uses the functionality.

See how you can add fun (or annoying ;) transitions to your S5 prezos, even on the iPhone:

Posted by Dion Almaer at 5:48 am
Comment here

+++--
3.5 rating from 15 votes

Monday, November 24th, 2008

Interactive iPhone Console using JSCocoa

Category: Debugging, JavaScript, iPhone

KUMAGAI Kentaro has created a JSCocoa based interactive console for the iPhone:

I’ve been struggling with transform property of UIView for long time. at last, I’ve decided to create UIMonkey that allows to manipulate the variables by trial and error through HTTP in Javascript with SpiderMonkey. Few days after I’ve started the project, I found JSCocoa through John Resig’s article and I abandoned my project and rewrited my codes on JSCocoa.

Now it works on the top of JSCocoa. It’s very helpful while inspecting the hierarchy of the view tree or size of the views etc.

Very cool stuff as you can run code on the fly and see it all change in the emulator. His article explains how you set it up, and gives you some fun examples.

Posted by Dion Almaer at 6:12 am
Comment here

+++--
3.5 rating from 4 votes

Friday, November 21st, 2008

iPhone for JavaScript Developers

Category: Mobile, iPhone

John has done a really good job at wrapping up information on the various options for JavaScript developers on the iPhone platform.

He discusses the various approaches:

  • JiggyApp: JiggyApp provides a full API for developing an application - apparently separate from most of the typical APIs. Arguably, though, the code ends up being relatively usable (jailbroken only :(
  • JSCocoa: JSCocoa is a full bridge that maps Cocoa development into JavaScript (instead of the typical Objective-C/Cocoa mapping). The result ends up working in both OS X and on the iPhone.
  • PhoneGap: PhoneGap is an application that exposes a few JavaScript APIs to pages running MobileSafari. Right now this includes Geolocation and access to the Accelerometer.
  • WebTouch: The other day “Dr Nic” wrote up an article on how he had used a WebKit instance (along with HTML, CSS, and JavaScript) to render a portion of his iPhone application.

I was chatting with someone on the PhoneGap team about their Android support. There is a play to be had to enable rich mobile applications all based on the Open Web stack that we know and love :)

Posted by Dion Almaer at 6:23 am
14 Comments

++++-
4.1 rating from 7 votes

Friday, November 14th, 2008

Using UIWebView (WebKit) in your iPhone App

Category: Mobile, iPhone

Dr Nic has shared his experiences using WebKit to implement part of your iPhone app (in his case SurfView):

Negatives

  • - (void)webViewDidFinishLoad:(UIWebView *)webView is slow. “You’re running an interpreter (JavaScript runtime) on top of a device with a small CPU and small memory. Go figure.”
  • The JavaScript bridge does not appear to block the main thread. This is a good/bad thing. You can invoke JavaScript code within the WebKit via your native Objective-C code.
  • The JavaScript bridge is one directional. From Objective-C/UIKit you can invoke JavaScript upon the WebKit and henceforth do wonderful things
  • Multiple languages in one project. Whilst we mainly just wanted to take a static HTML file, and dynamically update various elements with application data (e.g. the surf and weather conditions in the example above), we needed to do that via JavaScript.

Why you may want to do it

WebKit for rapid prototyping: WebKit exists and it is awesome at rendering HTML and CSS, with access to the powerful CSS3 transformations and webkit-specific bonus features.

It is highly likely that your designer can make something beautiful looking in Photoshop and cut it up into HTML + CSS. Comparatively, its highly unlikely they can cut it up into native Objective-C code.

WebKit isn’t the holy grail for non-Objective-C developers, but if your grand-poobar level skills are in JavaScript and HTML, and your Objective-C/iPhone skills are still catching up, then its a wonderful prototyping platform. Especially for static, complicated displays of data. Especially if that data includes HTML content from an external feed which needs to be rendered.

For Oakley’s Surf Report app, Anthony is toying with replacing some of the WebKit usage with native UI elements (normal UITableView with custom UITableViewCells) so that we can get back those precious seconds and give them to the user as a Christmas present.

A very nice read.

Posted by Dion Almaer at 8:21 am
3 Comments

++++-
4.6 rating from 7 votes

Friday, November 7th, 2008

CSS-VFX: CSS Visual Effects Tutorials and Components

Category: Apple, iPhone

We’ve talked a bit about Apple’s extensions to HTML and CSS; <canvas> has of course gone on to much fame and fortune. Charles Ying pointed us to his CSS-VFX project which aims to be

a collection of components and code examples that illustrate the power of CSS Visual Effects. So far, only 1 gem that illustrates a popular RIA user interface demo, “Cover Flow” is currently available. If you’d like to see more, please don’t hesitate to suggest something you’d like to see.

Charles has a blog entry with a video showing off a mobile Safari demo of using Apple’s CSS Visual Effects to create a Cover Flow interface:

The demo makes use of a variety of these extensions:

* zflow starts by loading each image from the images array. When each image is loaded, we scale the image to fit in a square region, and apply 3D CSS transforms to scale it in place.
* Reflections - zflow then takes the scaled image and creates a Canvas element that contains a gradient alpha mask of the image’s reflection (using a “reflect” function to do this) and positions the canvas element in place.
* Touch Controller - zflow creates a TouchController object, who’s job is to field touch events from Mobile Safari and calculate an appropriate offset.
* Clicking - zflow detects when no move events have been made, and zooms + rotates the focused image forward by setting a “CSS Transition”ed 3D transform on the focused image. Clicking again transitions the image back.
* Inertia - zflow achieves inertia by setting the “transition timing function” of the “tray” to an “ease-out” function, which slows things down. On the touch end event, we calculate the projected velocity and set the tray’s target position to that location. CSS Transitions handles the decay in velocity as the transition timing function executes — slowing the tray down gradually.

It makes you wonder how many folks are going to need to learn the SDK in the future…

Posted by Ben Galbraith at 7:00 am
5 Comments

++++-
4 rating from 6 votes

Thursday, October 9th, 2008

Exclusive iPhone in Action Chapter Downloads

Category: iPhone

Now that the NDA has been released, book publishers are finally able to get out their wares. Christopher Allen and Shannon Appelcline have written iPhone in Action, and have kindly given the Ajaxian community free downloads of a couple of the early access chapters:

I hope to see books that focus on what you can do with the Web APIs too of course ;)


This article is based on iPhone in Action, to be published January 2009. It is being reproduced here by permission from Manning Publications. Manning early access books and ebooks are sold exclusively through Manning. Visit the book’s page for more information.

Posted by Dion Almaer at 10:26 am
Comment here

++---
2 rating from 4 votes

Friday, October 3rd, 2008

iPhone Web Apps running at full screen

Category: Mobile, iPhone

I am so happy that the NDA mess is over! Clancy has written about how you can have your iPhone Web app run in full screen and has a demo app that shows it off:

HTML:
  1.  
  2. <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;" />
  3. <meta name="apple-mobile-web-app-capable" content="yes" />
  4. <meta names="apple-mobile-web-app-status-bar-style" content="black-translucent" />
  5.  

Posted by Dion Almaer at 4:03 pm
11 Comments

+++--
3.1 rating from 21 votes

Monday, September 29th, 2008

iPhone Safari 3D Navigation Menu

Category: Mobile, iPhone

Ben Putman has put together a nice iPhone Safari 3D navigation menu example that shows off the transforms and events available on the latest mobile Safari.

Ben told us:

In thinking of an interesting test, I've created a menu that you can rotate across a fixed y-axis with touch, allowing you to spin the menu around and see the depth and back of elements. There are also some examples of how animations can be used as you click and the menu unfolds. I also added a lightbox to examine how one might view some photos although it's not really practical in this form.

Open up the demo in your iPhone / Touch and also take a peak at the source to see what is going on, with snippets like this:

CSS:
  1.  
  2. .second_show {
  3.   -webkit-animation-name: 'second_show';
  4.   -webkit-animation-duration: 1s;
  5. }
  6.  
  7. @-webkit-keyframes 'second_show' {
  8.   from {    -webkit-transform: translateZ(0px) rotateX(180deg);}
  9.   to {    -webkit-transform: translateZ(100px) rotateX(0deg);}
  10.  
  11. }
  12. .second_hide {  -webkit-animation-name: 'second_hide';  -webkit-animation-duration: 1s; }
  13. @-webkit-keyframes 'second_hide' {
  14.   from {    -webkit-transform: translateZ(100px) rotateX(0deg);}
  15.   to {    -webkit-transform: translateZ(0px) rotateX(180deg);}
  16. }
  17.  

Posted by Dion Almaer at 6:42 am
1 Comment

++---
2 rating from 62 votes

Monday, September 22nd, 2008

PhoneGap: “AIR for the iPhone”

Category: iPhone

Dave Johnson calls PhoneGap "AIR for the iPhone" because this nice little hack, first created at an iPhone BarCamp, wraps the Web view with a container. This container gives the view access to APIs available on the device, that may not be available yet via WebKit alone. AIR provides a similar container for Flash and Ajax content on the desktop.

PhoneGap is a free open source development tool and framework that allows web developers to take advantage of the powerful features in the iPhone SDK from HTML and JavaScript. We're trying to make iPhone app development easy and open. For many applications a web application is the way to but in Safari you don't get access to the native iPhone APIs, and the that's the problem we're trying to solve.

It is written in Objective-C and allows developers to embed their web app (HTML, JavaScript, CSS) in Webkit within a native iPhone app. We're big advocates of the Open Web and want JavaScript developers to be able to get access iPhone features such as a spring board icon, background processing, push, geo location, camera, local sqlLite and accelerometers without the burden of learning Objective-C and Cocoa.

PhoneGap also has a web app that allows web developers to quickly package their web app into a native iPhone app by providing a URL, a name and icon graphic the web service with automagically create a native iPhone application. We haven't open sourced that code but we're going to soon.

PhoneGap was conceived at iPhoneDevCamp II by Nitobi developer Brock Whitten, Rob Ellis, freelance designer Colin Toomey and Eric Oesterle.

There are a few APIs available now, and others pending:

JAVASCRIPT:
  1.  
  2. // Location API
  3. // Feels a little ugly compared to passing in a closure. Using a hard coded name? :)
  4.   getLocation();
  5.  
  6.   //GAP will invoke this function once it has the location
  7.   function gotLocation(lat,lon){
  8.     $('lat').innerHTML = "latitude: " + lat;
  9.     $('lon').innerHTML = "longitude: " + lon;
  10.   }
  11.  
  12. // Accelerometer API
  13.  
  14.   function updateAccel(){
  15.     $('accel').innerHTML = "accel: " + accelX + " " + accelY + " " + accelZ;   
  16.     setTimeout(updateAccel,100);
  17.   }
  18.  
  19. // Camera (pending)
  20.   function takePhoto(){
  21.     var photo = gap:takePhoto();
  22.     return photo;
  23.   }
  24.  
  25. // Vibration (pending)
  26.  
  27.   function vibrate(){
  28.     gap:vibrate();
  29.     return false;
  30.   }
  31.  

You can take a peak at the open source code on github. For example, here is the code that wraps the iPhone location service:

[c]
@implementation Location

- (id)init{
NSLog(@"Gap::Location");
locationManager = [[CLLocationManager alloc] init];
[locationManager setDelegate:self];
return self;
}

+ (void)startTracking{
NSLog(@"starting location tracker");
[locationManager startUpdatingLocation];
}

+ (void)stopTracking{
NSLog(@"stopping location tracker");
[locationManager stopUpdatingLocation];
}

- (void)location{
NSLog(@"location is");
}

- (void)log{
NSLog(@"the location is...");
}

- (void)dealloc {
[locationManager release];
[super dealloc];
}

@end
[/c]

Posted by Dion Almaer at 7:33 am
5 Comments

+++--
3.8 rating from 19 votes

Thursday, September 18th, 2008

SVG working on the iPhone

Category: Mobile, SVG, iPhone

Dylan Schiemann wrote about how disappointing it was that the iPhone didn't support SVG:

Safari on the iPhone does not currently have support for SVG. Safari 3 beta on Mac and Windows is currently the best browser on the planet for SVG performance, so this is a somewhat disappointing omission. We are hopeful that by the end of the year, the iPhone will receive the Safari 3 upgrade, and along with that native support for SVG. For now, we’ll have to wait on dynamic charting and drawing tools due to no SVG and the lack of mousemove event handlers.

It appears that if you point your iPhone 2.1 browser to SVG content and tests it now works!

Posted by Dion Almaer at 6:41 am
9 Comments

+++--
3.3 rating from 6 votes

Wednesday, September 17th, 2008

iPhone Web App: Spin the Bottle

Category: Mobile, iPhone

Tomi Mickelsson has created a fun iPhone Web App called Spin the Bottle. You know, a Web app, not one that has to get into the Apple store.

You can check it out on the iPhone/Touch/emulator and you will see how Tomi uses the iPhone specific APIs, such as:

JAVASCRIPT:
  1.  
  2. function startTouch() {
  3.     setTimeout(hideURLbar, 100);
  4.  
  5.     document.body.ontouchstart = function(e) {
  6.         oldangle1 = 0; oldangle2 = 0; oldangle3 = 0;
  7.         //spinout();
  8.         cancelspin();
  9.     }
  10.  
  11.     document.body.ontouchmove = function(e) {
  12.         // prevent window scrolling!
  13.         e.preventDefault();
  14.  
  15.         if (timer_rot != 0)
  16.             return;
  17.  
  18.         var touch = e.touches[0]; // finger 1
  19.         var dx = centerx - touch.pageX;
  20.         var dy = centery - touch.pageY;
  21.         var angle = Math.atan2(dy, dx);
  22.  
  23.         oldangle3 = angle;
  24.         oldangle1 = oldangle2;
  25.         oldangle2 = oldangle3;
  26.  
  27.         var val = "rotateZ(" + angle + "rad)";
  28.         bottle.style.webkitTransform = val;
  29.         shadow.style.webkitTransform = val;
  30.         rot = angle;
  31.         //cancelspin();
  32.     }
  33.     document.body.ontouchend = function(e){
  34.         if (timer_rot == 0) {
  35.             var val = ((oldangle2 - oldangle1) + (oldangle3 - oldangle2)) / 2;
  36.             val /= 3;
  37.             if (val == 0.0)
  38.                 val = rand(0.3)+0.2;
  39.             else if (Math.abs(val) <0.3)
  40.                 val *= 3;
  41.  
  42.             //cancelspin();
  43.             startanim(val);
  44.         }
  45.     }
  46. }
  47. // remove our touch handlers
  48. function stopTouch() {
  49.     document.body.ontouchstart = null;
  50.     document.body.ontouchmove = null;
  51.     document.body.ontouchend = null;
  52. }
  53.  

Posted by Dion Almaer at 8:24 am
3 Comments

++---
2.6 rating from 14 votes

Monday, September 8th, 2008

3D CSS Transforms on the iPhone

Category: Mobile, iPhone

iPhone apps get a lot of attention and press and understandably so. For a lot of iPhone app developers, these tiny apps can turn into a tremendous cash cow making development for the phone platform invaluable. But considering that the iPhone is running Safari on it, it's surprising that we haven't seen a whole lot more buzz surrounding the use of the new Webkit functionality available to the browser.

Paul Bakaus, lead developer for the jQuery UI team, has started exploring the possibilities of what Safari can offer to web application developers:

So I wasn’t content with the things I’ve tried doing in Safari, and recently began digging through the documentation of the iPhone SDK and the actual CSS Transforms spec.

I was a bit skeptical when I first read about all the cool functions that work in Webkit iPhone, but nowhere else, because there was little documentation, and literally nothing done by other developers, no demos, no tests. I thought, surely, some students with too much free time must have jumped on that immediately?

Seems like Paul was on the right track as finding information on taking advantage of there features for the iPhone was scarce. So by using a iPhone simulator, Paul was able to start hacking at some of the built-in Webkit features, especially the 2D CSS Transforms.

Here comes the cool stuff: The perspective function seems to define how the other primitive functions behave.

Let’s have a look at a practical example: Take a look at the following three functions:

* rotateX - Rotates the element on the X axis.
* rotateY - Rotates the element on the Y axis.
* rotateZ - Rotates the element on the Z axis (By default, same as “rotate”)

Try these out - all three will give you flat, 2d animations, although they are, in fact, functions that use a 3D matrix. However, now change the -webkit-perspective property to 200, and try again. Now, you established virtual depth, and all three functions will give you incredible results.

The end result of Paul's tinkering is a very cool flip effect that is handled within the iPhone's browser and similar to that found in typical iPhone applications. While only a small demo, this opens up possibilities in how browser-based applications can react within the iPhone and what can be presented to mobile web users.

To see the demo, you will need an iPhone or an iPhone simulator.

Posted by Rey Bango at 8:54 am
3 Comments

+++--
3.9 rating from 12 votes

Tuesday, August 12th, 2008

Squirreling out the Fish on the iPhone

Category: JavaScript, Mobile, Performance