Sunday, September 23, 2012

iOS 6.0 Orientation

In iOS6,UINavigation Controller does not consult their children to determine whether they should autorotate.In another word iOS6 handle orientation by top-most controller.

The shouldAutorotateToInterfaceOrientation: method of UIViewController is deprecated. In its place, you should use the supportedInterfaceOrientations and shouldAutorotate methods.

iOS6 has three new method to handle orientation
// what we support
- (NSUInteger)supportedInterfaceOrientations 
    return UIInterfaceOrientationMaskAllButUpsideDown;

// should autorotate or not
- (BOOL) shouldAutorotate 
    return YES;

//initial orientation we want to have
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation 
    return UIInterfaceOrientationPortrait;
But where should we write those methods?

Saturday, September 22, 2012

How to use NSUserDefaults

//Use NSDate to determine that App first run or not
NSString *dateKey = @"dateKey";
NSDate *lastRead = (NSDate *)[[NSUserDefaults standardUserDefaults] objectForKey:dateKey];

// If lastRead is nil,App first run: set up user defaults.
if (lastRead == nil)
    NSDictionary *appDefaults  = [NSDictionary dictionaryWithObjectsAndKeys:[NSDate date], dateKey, nil];
    // do any other initialization you want to do here - e.g. the starting default values.
    [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"should_play_sounds"];
    // sync the defaults to disk
    [[NSUserDefaults standardUserDefaults] registerDefaults:appDefaults];
    [[NSUserDefaults standardUserDefaults] synchronize];

[[NSUserDefaults standardUserDefaults] setObject:[NSDate date] forKey:dateKey];

Thursday, August 30, 2012

Sunday, February 12, 2012

About initWithFrame and buttonWithType

There's two way to init UIButton

1.init by buttonWithType
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = frame;

2.init by initWithFrame
UIButton *button = [[[UIButton alloc] initWithFrame:CGRectMake(0.0f,0.0f,100.0f,45.0f)] autorelease];

Thursday, January 5, 2012

Wednesday, January 4, 2012




然而,Google Voice Search應用程式把接近感應器做了很好的利用,