gpt4 book ai didi

iphone - 如何为此代码实现计时器?

转载 作者:行者123 更新时间:2023-11-28 22:51:55 25 4
gpt4 key购买 nike

-(void) play
{
CMMotionManager *motionManager = [[CMMotionManager alloc] init];
[motionManager startDeviceMotionUpdates];

BOOL timeReached = NO;

while(!self.stopButtonPressed)
{
if(motionManager.deviceMotion.userAcceleration.y >= ... && motionManager.deviceMotion.userAcceleration.y <= ...)
{
//start timer
}
while(motionManager.deviceMotion.userAcceleration.y >= ... && motionManager.deviceMotion.userAcceleration.y <= ... && !timeReached)
{
if(//check timer & if timer is >=300ms)
{
timeReached = YES;
NSLog(@"acceleration on Y-axis stayed between ... & .. for at least 300ms");
}
}
}
}

最佳答案

看来你的做法是错误的;而不是运行时钟,您应该将 accelerometerUpdateInterval 设置为您正在寻找的任何内容并使用 startAccelerometerUpdatesToQueue:withHandler: 接收数据。

来自 the Apple documentation :

Handing Motion Updates at Specified Intervals

To receive motion dataat specific intervals, the application calls a “start” method thattakes an operation queue (instance of NSOperationQueue) and a blockhandler of a specific type for processing those updates. The motiondata is passed into the block handler. The frequency of updates isdetermined by the value of an “interval” property.

Accelerometer. Set the accelerometerUpdateInterval property to specifyan update interval. Call thestartAccelerometerUpdatesToQueue:withHandler: method, passing in ablock of type CMAccelerometerHandler. Accelerometer data is passedinto the block as CMAccelerometerData objects.

设置好所有内容后,让它运行。当您收到来自该 block 的完成通知时,请查看您收到的数据。

关于iphone - 如何为此代码实现计时器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11779240/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com