kar*_*yan 4 iphone nstimer ios
嗨,我是iOS的新手.现在我对这个概念感到困惑.我的概念就是当我点击按钮时我想获得当前时间(HH:MM:SS).在按钮上我做了一些重复的任务通过使用NSTimer.once我得到NSTimer sholud无效后的当前时间(nstimer呼叫每个(0.05f)).在这里我需要计算紧急时间与下一个minitue.thanks提前.不要误以为我我是愚蠢的英文.这是我现在还在的代码..
- (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;
}
Run Code Online (Sandbox Code Playgroud)
我这样做的方式很简单......
-(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;
}
- (void) scanButtonTouchUpInside {
[self performSelector:@selector(timerInvalidate) withObject:nil afterDelay:60.0];
if (check) {
position=CGPointMake(14.0f, 7.0f);
position1=CGPointMake(7.0f, 14.0f);
timer= [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(onTimer) userInfo:nil repeats:YES];
}
}
-(void)timerInvalidate
{
if ([timer isValid]) {
[timer invalidate];
}
}
Run Code Online (Sandbox Code Playgroud)
覆盖源取自https://github.com/jj0b/OverlayViewTester
| 归档时间: |
|
| 查看次数: |
269 次 |
| 最近记录: |