我正在监视我的应用程序中的俯仰和滚动值,我想监视它们是否在一秒钟内改变了 5 度,然后运行一个过程。目前我的代码如下所示:
CMAttitude *attitude;
CMDeviceMotion *motion = scoringManage.deviceMotion;
attitude = motion.attitude;
basePitch = degrees(attitude.pitch);
baseRoll = degrees(attitude.roll);
if((pitchfloat >= basePitch+5) || (pitchfloat <= basePitch-5)) {
}
if((rollfloat >= baseRoll+5) || (rollfloat <= baseRoll-5)) {
}
这被称为:
yprTime = [NSTimer scheduledTimerWithTimeInterval:(1.0/1.0) target:self selector:@selector(yprscore) userInfo:nil repeats:YES];
此过程与我的计时器一起每秒运行一次,但是当值更改时,它将多次运行该循环。
问题是 if 语句在那一秒内运行了 20 倍。