Pages

Wednesday, April 14, 2010

Gesture recoginization in iPhone SDK

For many magazine applications running on iPad, you easily see that the application detect your gestures for interactions on the content: rotate, swipe right to left (or left to right), tap. If we have to handle these gestures manually by code, it is not efficient.

So, Apple tries to make our developer life easier to breath by providing us a built-in mechanism to detect these common gestures on the latest iPhone SDK version.


You can find these APIs from UIGestureRecognizer class.
"A gesture-recognizer object (or, simply, a gesture recognizer) decouples the logic for recognizing a gesture and acting on that recognition. When one of these objects recognizes a common gesture or, in some cases, a change in the gesture, it sends an action message to each designated target object" - from Apple API documentation.


This class derives to:
1. UITapGestureRecognizer: presents the gesture that p fingers tapped the screen q times consecutively.
  • Input properties: numberOfTaps (q), numberOfFingers (p)
  • Output properties: location, touches
2. UISwipeGestureRecognizer: represents the gesture that p fingers tapped the screen q times consecutively.

3. UIRotationGestureRecognizer: looks for rotation gestures involving two touches. When the user moves the fingers opposite each other in a circular motion, the underlying view should rotate in a corresponding direction and speed.

4. UIPinchGestureRecognizer: represents the gesture that 2 fingers moving towards or away from a center point. This gesture is usually used for scaling a view.
  • Input properties: scaleThreshold
  • Output properties: scale, velocity, anchorPoint, transform
scaleThreshold is the critical scale the fingers must first move apart/together before this recognizer could fire.

5. UILongPressGestureRecognizer: represents the gesture that p fingers moved/stayed on the screen continuously for T seconds.
  • Input properties: numberOfFingers (p), delay (T), allowableMovement
  • Output properties: touches, centroid, startPoint
6. UIDragRecognizer: represents the gesture that 1 or more fingers moving on the screen for a distance of d. Optionally it may also be constrained to moving only within an angle of θ ± Δθ.
  • Input properties: minimumDistance (d), angle (θ), maximumDeviation (Δθ), restrictsToAngle
  • Output properties: touch, startPosition, startAngle
Note that the angles are in radians.
7. UIPanGestureRecognizer: represents the gesture that 1 or more fingers moving on the screen for a relatively large distance. This gesture is usually used for scrolling, and is used by UIScroller and UIScrollView.
  • Input properties: directionalLockEnabled
  • Output properties: offset, velocity, transform
8. UITapAndAHalfRecognizer: represents the gesture that 1 finger tapped the screen q times consecutively, and then moved/stayed on the screen.
  • Input properties: numberOfFullTaps (q), allowableMovement
  • Output properties: touch


An example for how to use these API:
UISwipeGestureRecognizer *swipeRecognizer = [[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(DidSwipe:)] autorelease];

By default this line of code detect the swipes from left to right.

If you want to detect a swipe from right to left add the below line after the above line:
swipeRecognizer.direction = UISwipeGestureRecognizerDirectionLeft;

On 1 view, you can add many gesture recognizers to handle different interactions by using below function
[self.view addGestureRecognizer:swipeRecognizer];

After that, just implement the [DidSwipe] method we already registered above:
- (void) DidSwipe:(UISwipeGestureRecognizer*)sender{
   Do something...
}


Refs:
+ http://iphonedevwiki.net/index.php/UIGestureRecognizer
+ iPhone SDK 3.2 API document

Happy coding!

Monday, March 29, 2010

Top reasons you should NOT join to the mobile team at Pyramid Consulting

1. There are many exciting things in our activities. You may DIE if you cannot control your emotions.
2. There’re many interesting things to learn. You will be overloaded with knowledge and new things – but useful for your work & your life.
3. Your friends may envy you because you can do many wonderful & crazy things.
4. We’re NOT colleague only. We’re brothers in a family. If you’re afraid of having more brothers, don’t join us.
5. We share all things together, all troubles & happiness, both in work & life. If you’re afraid of sharing, this team is not a good choice for you.
6. All members are courage men. Dare to talk, dare to do, dare to share.
7. You cannot stand some our bad habits for relaxing at the weekend: drink & eat dog meat, play some games – may be good (or bad) for your health.
8. If you can think of more reasons NOT to join into mobile team, please share to us.

Monday, March 15, 2010

Multiple phone application framework

Multiple phone application frameworks are: frameworks/solutions that allow developers to build applications to run on multi phone devices.

Recently, there' re some companies trying to build these solutions. This may make a new trend in developing application on mobile: build once, run every where (at least on most popular mobile platform) :)

Actually, this idea is good. However, it meets some troubles:
  • Mobile Platform + their SDKs are changes frequently. The multiple phones application frameworks cannot catch up with the speed of change of the platform + SDKs. Mobile developers prefer to have chance to use the latest APIs to make use of the strength of the newest platform.
  • On some popular mobile platforms (Apple, Android, BlackBerry), there' re always some private APIs - means some APIs are not official public. Developers must work on the real platform & SDK to use these APIs. The multiple phones application frameworks cannot wrap these APIs into their library because it needs to be more generic to be used in a common way.


Anyway, we should wait.

You can checkout a list of some open source multiple phone application frameworks here

Thursday, December 3, 2009

The Presentation Secrets of Steve Jobs

This is a book bought on Amazon. Below is a slide summary for content inside. It makes me very interesting.

Wednesday, December 2, 2009

iPhoneARKit and Point Of Interest apps on iPhone

A point of interest, or POI, is a specific point location that someone may find useful or interesting. An example is a point on the Earth representing the location of the Space Needle, or a point on Mars representing the location of the mountain, Olympus Mons.

The term is widely used in cartography, especially in electronic variants including GIS, and GPS navigation software. In this context the synonym waypoint is common.
(from wikipedia)

iPhoneARKit is a great tool for developing POI (Point Of Interest) apps on iPhone. We've just done the first demo based on this library. It's a simple application to detect POI locations in camera view and show related information (in the context of this demo - is shops with coupons)


Bee Buzz Finder from Vinh Nguyen on Vimeo.


Many business ideas comes from this, right?