嗨,我是一种新的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