Tapku

Archive for the ‘Development’ Category

Using Geometry to Create 2D Physics Motion of A Flicking Gesture on the iPhone

Monday, August 24th, 2009

In Album Shuffle, you can move and flick albums across the screen. After a user ends a touch event by taking their finger off the screen, the album will still move across the screen as if it were a real physical environment. This article will focus on figuring out how to move the object in a semi-realistic way after the touch event ends. To figure out the velocity of just how fast the object is moving, we’ll need to brush up on some old geometry, which the article will cover. You can take a look at the code used to calculate the motion.

Recording touch information

When a user touches the screen, the view that receives that touch event through the touchesMoved function. The key to figuring out the velocity of the touch is based on how often this function is called. The touchesMoved function isn’t called after the touch moved every pixel, instead the function is called based more or less on time. (Note: if a user touches the screen and doesn’t move their finger, the function won’t be called either because the touch event didn’t move, hence the name touchesMoved. ) If a user touched across a large area of the screen very quickly, then the touchesMoved function might be called two or three times. If that same touch movement was done slowly, then the touchesMoved function might be called 20 or 30 times. The key is that each time an event is sent, the new coordinates are sent. So by remembering the last two touch events sent through the touchesMoved function, based on the gap between these two coordinates, a velocity can be determined.

Geometry Time

So after a touch event occurs, the touchesEnded function is called on the view. At this point, its time to use the last two touch points given to figure out the velocity. Here is where the good old geometry math will help, the distance between these two points is

Distance Between Two Points Formula

Distance Between Two Points Formula

The higher this number, the faster and further you need to animate the object across the screen (You’ll need to divide this number by some constant so the object animates proportionate to the motion). The direction can be figured out based on these two points as well. When animating, the time of an animation can be held constant because an object that needs to travel further will travel faster to a spot because it needs to travel a farther distance in a shorter time.

Faster Animation on an iPhone: Quartz vs Core Animation

Saturday, August 22nd, 2009

Article moved to: http://devinsheaven.com/faster-animation-on-an-iphone-quartz-vs-core-animation/

Cocoa Touch: iPhone Calendar Month View Class

Wednesday, August 12th, 2009

CONTENTS OF ARTICLE ARE OUTDATED.

calendarview

You won’t find that cool calendar view class you see in the Calendar app in the iPhone 3.0 SDK, but you will find it in the open source Tapku Library. The tapku library calendar view looks (almost) exactly like the one you see in the Calendar app and it acts the same way with the ability to add an indicator for each day that has some piece of information associated with it. The rest of article will step you through using the TKCalendarView and TKCalendarViewController.

The easiest way to use the calendar view is to use the TKCalendarViewController and implement the following Calendar View delegate methods.

- (NSArray*) calendarView:(TKCalendarView*)calendar itemsForDaysInMonth:(NSDate*)monthDate;

- (void) calendarView:(TKCalendarView*)calendar dateWasSelected:(NSInteger)integer ofMonth:(NSDate*)monthDate;

- (void) calendarView:(TKCalendarView*)calendar willShowMonth:(NSDate*)monthDate;

The first delegate method, the one that expects back an NSArray, is the function that sets up the marks for each day in the month. The monthDate variable is the time-stamp for the first day in that particular month requested, like for instance August 1st 2009 0:00:00.0. The array returned should be filled with 31,30 or 28 (however many days are in that particular month) NSNumber objects with boolean values. In terms of programming, this function is a good time to query a database, and store the objects in memory so you can easily display information when a day is selected.

The dateWasSelected method is fired by the Calendar view every time the user selects a new day or they switch months. The monthDate variable again is the time-stamp day for the first of the month and the integer variable is the actual day of that month. You may wonder why this isn’t another date variable. This is just to keep the memory and processor use down as well as make it easier to code on the controller side.

The willShowMonth method will fire when months are swapped in and out. This method is useful when you want to adjust objects in the view because of the resizing of the calendar. Recall, the Calendar app has a UITableView stuck to the bottom of the Calendar view. When the calendar switches months and calls that delegate method, you can resize something like a table view to the new frame height of the calendar view.

To use the Calendar View, download the Tapku Library from github and make sure to check out view and view controller classes as well as the demo app to see the class in action.

Don't Touch The iPhone 3.0 Music API

Tuesday, August 4th, 2009

After confirming with colleagues also trying to get their applications that utilize the Music API, included in the iPhone OS 3, it appears applications that utilize this API will be ushered aside in an app approval waiting cell. Speaking from experience, I currently have an application up in holding which is not only a bummer for me, but also everyone who might want to download it (for free). Some developers have received notices from Apple that the review time will take longer, but any and all details including a time table for approval thereafter are not stated in their emails. Any attempts to contact them through email are met with canned useless answers.

apple-iphone-music-coverflow

My suggestion to developers is to stay away from this cool and enticing API until we have some answers to why Apple doesn’t want to approve them. If you don’t heed my advice, beware , your efforts may get trapped in this app approval cell and not get out.

Cocoa Touch Tutorial – Receiving & Using the Shake API for iPhone OS 3

Tuesday, August 4th, 2009

Article has moved here: http://devinsheaven.com/cocoa-touch-tutorial-receiving-using-the-shake-api-for-iphone-os-3/.

The iPhone App That Never Was

Monday, August 3rd, 2009

Audio Mixing App

Back in May, I was pondering an iPhone app that was outside the box. Something no one else had done. A mixer application for the iPhone. Soon after, I created a mockup of the application which is the main reason why I’m writing this article. So I can share this mockup. I wanted the interface to be simple with just a pitch and volume control for each track.  I was skeptical all along that an application with such abilities as mixing music could exist on the iPhone and output the audio that way I would have hoped. Here are some reasons why the application couldn’t be:

Why it wouldn’t work

If you know anything about DJing, you’d want to create two channels of audio. One channel to go to the DJ’s headphones and another to go to the speakers. Well, the iPhone in theory is perfect for this because the 30-pin dock connector could relay one signal, and the headphone jack could relay another. In reality, only one signal can come out of the device.

The second red flag was the iPhone’s ability to play certain file formats. MP3, AAC and Apple Loseless can’t be played simultanouesly.  The audio formats that can be played back togther are formats like Linear PCM or AMR. Don’t worry, I’ve never heard of these file formats either. The documentation fails doesn’t mention anything about WAV or AIFF in this section. I figured if you couldn’t play your iTunes library, there would be little point to application.

Since I’ve research this topic, Apple has unveiled the iPhone 3GS which is a big speed increase compared to the 3G. The documentation from what I can tell doesn’t state any changes now that the faster iPhone is out. Oh well, there is always the Tablet Mac…. (don’t steal my UI). Those sliders took forever to make!

Cocoa Tutorial: Passing Messages Between Objects: Notifications, Delegates and Target-Action

Thursday, July 23rd, 2009

Article moved here: http://devinsheaven.com/cocoa-tutorial-passing-messages-between-objects-notifications-delegates-and-target-action/

Creating UITabbar / UIToolbar Icons for iPhone in Adobe Illustrator

Monday, July 20th, 2009

Article has moved: http://devinsheaven.com/creating-uitabbar-uitoolbar-icons-in-adobe-illustrator/

Free Library of iPhone UI classes

Friday, July 3rd, 2009

Having worked on the iPhone for almost a year now, I’ve reused so much code, and create basically the same classes over and over again. So instead of continuing on this path, I’ve decided to create a library of common classes like table view cells, and loading indicators. The repository is hosted on github, and I plan on adding more and more to the library soon. Right now, the library has mostly a lot of labeled table view cells. You can see these cells used throughout To-Do Lists. Another class is LoadingHUDView which looks similar to a alert view, but instead is good for tell the user that stuff is loading.