2009年8月27日 星期四

UIViewController

originally in view of A controller,
then show view of B controller:
[self presentModalViewController:testViewController animated:YES];
[testViewController release];

jump back to view of A controller
[self dismissModelViewControllerAnimated:YES];

UIButton

ex:
UIButton *backButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
backButton.frame = CGRectMake(380, 260, 80, 30);
[backButton setTitle:@"Back" forState:UIControlStateNormal];
[backButton addTarget:self action:@selector(backButtonClicked:)
forControlEvents:UIControlEventTouchUpInside];

2009年8月26日 星期三

core animation

three basic steps for core animation:
1. beginAnimations
2. setAnimationDuration
3. commitAnimations

shorter word to access app delegate

#define AppDelegate (MyAppDelegate *)[[UIApplication sharedApplication] delegate]


then use AppDelegate in the code


do something in the future

1. execute function in the future

- (void)performSelector:(SEL)aSelector withObject:(id)anArgument afterDelay:(NSTimeInterval)delay;

ex: [self performSelector:@selector(sing:) withObject:nil afterDelay:1.4];


2. use timer

(NSTimer *)timerWithTimeInterval:(NSTimeInterval)ti target:(id)aTarget selector:(SEL)aSelector userInfo:(id)userInfo repeats:(BOOL)yesOrNo;

ex: [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(test:) userInfo:nil repeats:YES];
note:
to delete timer, use invalidate method
ex:
-(void)test:(NSTimer*)timer
{
[timer invalidate];
}

2009年8月25日 星期二

iphone view size

UIInterfaceOrientationLandscapeLeft:

w:480 h:320

2009年8月18日 星期二

modify view class for view controller

from view controller's xib,
click on view,
from inspector panel, click information ,
change class to the view class you want

2009年8月13日 星期四

game kit bluetooth connection problem

try
method 1:
turn off wifi

method 2:
restart iphone

2009年8月12日 星期三

trigger iphone vibrate

1. include AudioToolBox.framework

2.
#import
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);

2009年8月4日 星期二

get current time

NSCalendar *calendar= [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSCalendarUnit unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit |
NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit |
NSSecondCalendarUnit;
NSDate *date = [NSDate date];
NSDateComponents *dateComponents = [calendar components:unitFlags
fromDate:date];
NSInteger year = [dateComponents year];
NSInteger month = [dateComponents month];
NSInteger day = [dateComponents day];
NSInteger hour = [dateComponents hour];
NSInteger minute = [dateComponents minute];

[calendar release];

2009年8月1日 星期六

animation delegate

1. initial
// if want to change something, such as move a UIImageView,
// then pass this UIImageView as context argument
[UIView beginAnimations:@"test" context:nil];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:
@selector(animationDidStop:finished:context:)];
[UIView commitAnimations];

2. when animation finish, animationDidStop is called

- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished
context:(void *)context

NSThread

do sth on main thread , and wait until done

ex:

[self performSelectorOnMainThread:@selector(loadPhoto) withObject:nil waitUntilDone:YES];