'Cool'에 해당되는 글 1건

  1. 2010.06.24 iPhone Cool Projects
아이폰어플개발정보2010. 6. 24. 14:13
iPhone Cool Projects

Ch1. MVC architecture using game object

Formic: simplified version of the game Frenzic

Good games are not created on the drawing board; you have to play them to see what’s great and what’s not, and alter accordingly.

* 2 approaches to the problem of synch. between game and view

1. Pieces going into an animation would be removed from the normal view storage and put into a special animation queue. View controller queries the game object.

2. Block the game until the animation is finished. (simple but not acceptable all the time)

* UIView: properties that can be animated

- frame, bounds, and center (i.e., position)

- alpha (i.e., transparency)

- transform (i.e., size)

* series of animations

- method 1

[UIView setAnimationDelegate:self]; [UIView setAnimationDidStopSelector:@selector(animationDidStop:finish:)];

- method 2

performSelector:WithObject: afterDelay:

** iPhone-Specific Functionality

* Activation and deactivation

- (void)applicationWillResignActive:(UIApplication *)application;

: sent to app delegate

: when the user pressed sleep button

: stop all timers, animations, and sound and go into pause state

- (void)applicationDidBecomeActive:(UIApplication *)application;

* Memory warnings

- (void)didReceiveMemoryWarning;

: sent to all view controllers

: When your application receives memory warnings but fails to free enough memory, the operating system will simply shut down your application. (vs. crash)

* Saving and restoring the game (when quitting and opening the application)

- applicationDidFinishLaunching:

- applicationWillTerminate:

: sent to app delegate

Ch2. P2P Netwokring (POSIX sockets using UDP, Bonjour)

Layers must be hosted by a view. When paired with a view, the view must provide event-handling for the underlying layers, while the layers provide display of the content.

uint32_t num = 'SpHn';// wow!~

#pragma pack(1)

#pragma options align=reset

self <- current object

_cmd <- current method!!!

performSelectorOnMainThread:// call main tread's method

NSMutableDictionary really dislikes being mutated while it’s being iterated.

Ch3. Threading

Threading enables you to add the responsiveness to your application.

Each thread is responsible for its own autorelease pool.

race condition: the timing of the threads' access to resources can causes unexpected results.

NSLock *myLock = [[NSLock alloc] init]; // mutex

[myLock lock];

// critical section

[myLock unlock];

NSObject's -performSelectorInBackground: withObject: method is just about the same as NSThread class method +detachNewThreadSelector

run loop processes the events that you use to schedule work and coordinate the receipt of incoming events.

Ch4. Multi Touch

"principle of least embarrassment"

UIViews and most subclasses default to userInteractionEnabled, but multipleTouchEnabled is usually disabled.

For each of the touchesX:withEvent:, the touches set will only contain the changed touches, whereas the UIEvent always contains the complete set of active touches.

NSSet* allTouches = [event touchesForView:self];

If the size of the changed touches set is the same as the size of the event’s touchesForView set, we know the last fingers are being lifted from the screen.

A UITouch object’s address does remain constant throughout its life, so Apple recommends using these addresses as keys in a CFDictionary (not NSDictionary).

A multitouch control rarely needs to track an individual touch for its lifetime.

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event;

If we override this, we can arrange for touches to be delivered to our class, not the subclass.

Many touch interfaces rely on physical metaphors: your finger interacts with controls as though they were physical machinery with weight, momentum, and inertia.

Note that the two GadgetView objects are siblings of the BackgroundView, not children of it. This ensures they’re not disrupted when the background image changes. (?? sibling vs. children ??)

// single finger drag

UITouch* anyTouch = [touches anyObject];

lastMove  = anyTouch.timestamp;

CGPoint now  = [anyTouch locationInView: self.superview];

CGPoint then  = [anyTouch previousLocationInView: self.superview];

dragDelta  = CGPointDelta(now, then);

self.center  = CGPointApplyDelta(self.center, dragDelta);

iPhone’s screen refresh rate: 60 fps

atan2f(delta.height, delta.width)

// gets us the angle described by the line

between the points.

Ch5. cocos2d

Designing a virtual world

- Design the space: constraints, boundaries, friction, elasticity, gravity, lighting, ...

- Define the rules: how the objects interact with the space

- 3D:rendering is based on sets of 3D coordinates mapped to textures

- 2D: 2D coordinates mapped to sprites


Ch6. Streaming Audio

It’s very important that you always check the return codes from audio API calls. Even if you don’t do any specific error handling, you should at least log any errors. Having these log entries helps a ton when debugging mysterious audio problems.

Core Audio was designed with the goal of complete agnosticism across all file formats and audio codecs.

All audio files are treated as a series of audio packet data that are enclosed in an envelope. The encodingformat (AAC, ...)of the packet data is distinct from the envelopeformat (MPEG4-Part14 or MP4, M4A, ...).

M4A isn’t the best format for streaming audio. It contains a significant amount of data at the beginning defining the structure of the file.

Audio Data Transport Stream (ADTS) can play audio with a smaller up-front data size and more easily support playback of audio starting in the middle of a file.

ringer volume vs. media volume

session category...

By declaring our session as MediaPlayback, the operating system will know to keep our application running when the device is locked, so we can continue playing music indefinitely.

we deactivate the session by calling AudioSessionSetActive(NO) so that the phone may hibernate.

AudioFileStream may generate a magiccookie, and if it does, it needs to be passed onto AudioQueue to enable proper decoding.

iPhone allows only one AudioQueue to exist at any time.

testing URL



Ch7. Core Location, XML, SQLite

SQLite Database Manager (http://sqlitebrowser.sourceforge.net/)

SCNetworkReachability() tests network reachability

SCNetworkReachabilityFlags flags;

SCNetworkReachabilityRef reachability =



SCNetworkReachabilityGetFlags(reachability, &flags);

BOOL reachable = ! (flags &


NSURLConnection *conn; NSURLRequest *request = 



if ([NSURLConnection canHandleRequest:request] && reachable)


conn = [NSURLConnectionconnectionWithRequest:request delegate:self];

if (conn)


self.predictionXMLData = [NSMutableDatadata];



// get distance in metres

- (CLLocationDistance)getDistanceFrom:(const CLLocation *)location

XPath Objective-C wrapper (http://cocoawithlove.com)

// sort

NSSortDescriptor *sort = [[NSSortDescriptoralloc] initWithKey:@"distance"



[sort release];

출처 : http://blog.naver.com/PostView.nhn?blogId=gonagi&logNo=150074852198
Posted by 오늘마감

댓글을 달아 주세요