Tuesday, June 23, 2009
iPhone dev Stupidity 27: Rect in different views
Monday, June 22, 2009
iPhone dev Stupidity 26: Position
Friday, June 19, 2009
iPhone dev Stupidity 25: Read The Sample Code of Apple
Wednesday, June 17, 2009
iPhone dev Stupidity 24: Unit Test Setup
* Sen:Te's guide
Configure the project
1. Add a ‘Unit Tests’ target
From the Project > New Target… menu add a Mac OS X > Cocoa > Unit Test
2. Configure ‘Unit Tests’ through its inspector:
In the ‘Build’ tab delete all ‘User-Defined Settings’ and the ‘Other Linker Flags’ setting.
In the ‘General’ tab add the Foundation and SenTestingKit frameworks
(/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator2.2.sdk/Developer/Library/Frameworks/SenTestingKit.framework)
3. Make the application a dependency of ‘Unit Tests’:
In the ‘General’ tab of the application add ‘UnitTests’ as a direct dependency.
Write some tests
4. Avoid compiling tests outside of the simulator:
* StackOverflow discuss:
I also changed Base SDK to be Device - iPhone OS 2.2 and other linker flags to -framework Foundation -framework SentestingKit
Tuesday, June 16, 2009
iPhone dev Stupidity 23: Keep Iterator Valid when Removing Object
iPhone dev Stupidity 22: Forget to Remove from Superview
Monday, June 15, 2009
iPhone dev Stupidity 20: Animation Fast
From StackOverflow:
"Creating 30 new animations a second is a really bad idea, and not how Core Animation was intended to be used. Core Animation was designed around the idea that you tell the system where you want your layer (or layer-backed view) to end up, and it figures out the rest, including how many frames to drop to run the animation in the time frame you provide. The animations themselves will run on a background thread, but I believe there's a little setup that needs to be performed first which takes place on the calling thread (usually the main thread). This setup might take longer than 1/30th of a second, which would overload your main thread.
You goal should be to minimize the amount of interaction with Core Animation. If you have a complex, but scripted, motion path (or other property change), set it all up ahead of time using a CAKeyframeAnimation and just call that animation once. If there's something about the motion of your object that needs to be altered in response to user input, only do that when you get the actual input. Changing a property of a CALayer mid-animation will cause it to smoothly move from the middle of its current motion path to its new destination.
If you work with Core Animation in this fashion, you can simultaneously animate up to 50 moving translucent layers at 60 FPS on the iPhone."
Sunday, June 14, 2009
iPhone dev Stupidity 19: using shark for iPhone
*) Launch the app on the device
*) Launch /Developer/Applications/Performance Tools/Shark in the Finder
*) Choose Sampling>Network/iPhone menu item
*) Choose your device in the window
*) Choose the application from the popup menu under Target so only your app is sampled
*) Click Start button in window
*) Do stuff in test application
*) Click Stop in window
iPhone dev Stupidity 18: Disable iPhoto When iPhone connected
Tuesday, June 09, 2009
iPhone dev Stupidity 17: Clip Image from CGContext
// create CGImageRef frome UIView context
CGImageRef imageref;
imageref = CGBitmapContextCreateImage(context);
// convert CGImageRef to UIImage;
UIImage *uiImage;
uiImage =[UIImage imageWithCGImage:imageref];
CGImageRelease(imageref);
Monday, June 08, 2009
iPhone dev Stupidity 16: Subview Index
Sunday, June 07, 2009
iPhone dev Stupidity 15: Category Limitation
Saturday, June 06, 2009
iPhone dev Stupidity 14: UIFont size
To understand the properties of UIFont (from Microsoft doc on opentype ):
Log info for a 42 pointsized system font:
> font size 21 50
> Font Helvetica properties: leading 50.000000, ascender 39.340820, capheight 30.534000, descender -9.659180, pointSize 42.000000
Leading: the height of the line.
To get the tight bounding box of a character, height = ascender.
And to center a char at the center of a view:
CGSize font_size = [text_ sizeWithFont: font_];
int x = (VIEW_WIDTH/2) - (font_size.width/2);
int y = (VIEW_HEIGHT/2) - (font_size.height/2);
int w = font_size.width;
int h = font_.ascender;
return CGRectMake(x, y, w, h);
}
Thursday, June 04, 2009
iPhone dev Stupidity 13 - Transparent View
The other thing you need to do is make sure that the opaque property is set to NO. Ordinarily, opaque should be set to YES as an optimization, but that optimization isn't available to us if we want stuff to show through from below."