網頁

顯示具有 Timer 標籤的文章。 顯示所有文章
顯示具有 Timer 標籤的文章。 顯示所有文章

2012年11月15日 星期四

xcode delay


[iOS Dev] 自動出現鍵盤並延遲出現 UIKeyboard auto show and delay



- (void)enableKeyboard {
 [self.textField becomeFirstResponder];
}

- (void)viewDidLoad {
    [self performSelector:@selector(enableKeyboard) withObject:nil afterDelay:.3]; 
    [super viewDidLoad];
}

2012年6月28日 星期四

Countdown Timer in Xcode

How to create a countdown timer in iPhone app.

.h
 
@interface ViewController : UIViewController
{
    IBOutlet UILabel  *countDownLabel;

    NSTimer *gameTimeCount_Timer;
    
    int gameCountDown_int;    
    int gameCountDown_minutes, gameCountDown_seconds;

    
}
@property (nonatomic, retain) UILabel *countDownLabel;
.m

 
#import "ViewController.h"

#define GAME_COUNTDOWN    71


@interface ViewController ()

@end

@implementation ViewController
@synthesize countDownLabel;


- (void)viewWillAppear:(BOOL)animated {
    
    gameCountDown_int = GAME_COUNTDOWN;
    
    gameTimeCount_Timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(GameTimer_Count) userInfo:nil repeats:YES];
    
}

- (void)GameTimer_Count {
    

    if (gameCountDown_int > 0)
    {
        gameCountDown_int-- ;
        
        gameCountDown_minutes = (gameCountDown_int % 3600) / 60;
        gameCountDown_seconds = (gameCountDown_int % 3600) % 60;
        
        countDownLabel.text =   [NSString stringWithFormat:@"%02d:%02d", gameCountDown_minutes, gameCountDown_seconds]; 
    }
    
}