嗨,我是一種新的iOS.Now我混淆了這個概念..概念是,我想獲得當前時間(HH:MM:SS)時我點擊button.Inside按鈕我做了一些重複的任務,通過使用NSTimer
。一次我得到當前時間NSTimer sholud失效後(nstimer是每個調用(0.05f))。在這裏,我需要計算按下時間與下一個minitue.thanks advance.sorry不要把我誤認爲我是愚蠢的英語。 這裏是我現在還在代碼..從下一個計算當前時間然後NSTimer不應該工作
- (void) scanButtonTouchUpInside {
if (check) {
position=CGPointMake(14.0f, 7.0f);
position1=CGPointMake(7.0f, 14.0f);
check=NO;
timer= [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(onTimer) userInfo:nil repeats:YES];
}
else
{
//animation stop code here.................
if ([timer isValid]) {
[timer invalidate];
}
check=YES;
NSLog(@"stopppppppp.....................");
// overlayGraphicView.frame = CGRectMake(30, 100, 32, 32);
// overlayGraphicView1.frame = CGRectMake(30, 152, 32, 32);
}
}
-(void)onTimer
{
overlayGraphicView.center = CGPointMake(overlayGraphicView.center.x+position.x,overlayGraphicView.center.y+position.y);
if(overlayGraphicView.center.x > 320 || overlayGraphicView.center.x < 0)
position.x = -position.x;
if(overlayGraphicView.center.y > 480 || overlayGraphicView.center.y < 0)
position.y = -position.y;
overlayGraphicView1.center = CGPointMake(overlayGraphicView1.center.x+position1.x,overlayGraphicView1.center.y+position1.y);
if(overlayGraphicView1.center.x > 320 || overlayGraphicView1.center.x < 0)
position1.x = -position1.x;
if(overlayGraphicView1.center.y > 480 || overlayGraphicView1.center.y < 0)
position1.y = -position1.y;
}
採取覆蓋源? –
感謝@nathan hegedus我以不同的方式完成了這項工作 – karthikeyan