草庐IT

NStimer、CADisplayLink、dispatch_source_t

全部标签

ios - 是否可以使用NSTimer将越狱的iPhone从深度 sleep 中唤醒?

注意:在编辑的更下方,有简单的代码可以生成问题,而没有我的原始程序的全部复杂性。我正在尝试为越狱的iOS编写一个闹钟应用程序。我已将UI设置为用于调度警报的独立应用程序,然后将警报信息保存到磁盘。保存文件由始终运行的启动守护程序读取,该守护程序实际处理警报。我这样安排警报(在守护程序中编辑:)(NSDate*fireDate较早计算):NSTimer*singleTimer=[[NSTimeralloc]initWithFireDate:fireDateinterval:0target:selfselector:@selector(soundAlarm:)userInfo:alarmr

objective-c - 使用 NSTimer 的秒表错误地在显示中包含暂停时间

这是我的iPhone秒表代码。它按预期工作,并在单击按钮时停止和恢复。但是,当我点击“停止”时,计时器不会停止在后台运行,而当我点击“开始”恢复它时,它会更新时间并跳到当前位置而不是从那里恢复停止的时间。如何停止NSTimer?发生这种情况的原因是什么?@implementationFirstViewController;@synthesizestopWatchLabel;NSDate*startDate;NSTimer*stopWatchTimer;inttouchCount;-(void)showActivity{NSDate*currentDate=[NSDatedate];NS

ios - 如何在后台运行 NSTimer 并在 iOS 中休眠?

我在stackoverflow中发现了很多关于NSTimer在后台运行的帖子。但是我没有找到任何解决方案。在我的应用程序中,我在后台播放声音,并设置定时器在到达该时间时停止播放音乐。所以我需要运行我的NSTimer后台(意思是当点击主页按钮并让iPhone休眠时)。我该怎么做? 最佳答案 //NSTimerrunwhenappinbackground[[UIApplicationsharedApplication]beginBackgroundTaskWithExpirationHandler:nil];loop=[NSTimers

ios - 在后台运行 NSTimer 或 UILocalNotification

如何在iOS上执行倒计时?首先,我尝试了NSTimer。然后我发现当应用程序进入后台时NSTimer无法工作。其次,我用过counterTask=[[UIApplicationsharedApplication]beginBackgroundTaskWithExpirationHandler:^{}];让NSTimer在后台工作。但后来我发现iOS只允许应用程序在后台运行不超过600秒(10分钟)。我不知道如何让NSTimer在后台运行超过10分钟。第三,我厌倦了使用NSLocalNotification,但它运行良好。但我想做的是通过调用一个方法来暂停播放音乐。我发现UILocalN

ios - 当方法重新运行时,在方法中循环 dispatch_after 会导致许多同时调度

我正在创建一个简单的游戏。我有以下代码:-(void)doStuff{doubledelayInSeconds=[NSNumberrandomFloatBetweenLowerBound:0.8fupperBound:2.6f];//OwncategoryonNSNumberreturnsrandomfloat.dispatch_time_tpopTime=dispatch_time(DISPATCH_TIME_NOW,(int64_t)(delayInSeconds*NSEC_PER_SEC));dispatch_after(popTime,dispatch_get_main_que

ios - 在 dispatch_once(&onceToken, ^{

+(Service*)sharedInstance{staticLocationService*instance=nil;staticdispatch_once_tonceToken;dispatch_once(&onceToken,^{我正在使用上面显示的代码在我的应用程序中创建服务的单例实例。这是从“AppDelegateapplication:willFinishLaunchingWithOptions:”调用的。对于大多数用户来说,这段代码工作正常。但是对于2个用户,应用程序在“dispatch_once(&onceToken,^{”行崩溃。他们删除了该应用程序并重新安装了它。

objective-c - 如何使用 CADisplayLink 在 CMRotationMatrix 上应用过滤器

如何在CMRotationMatrix上应用过滤器?也许是卡尔曼滤波器。我需要修复CMRotationMatrix(transformFromCMRotationMatrix)的噪声,以获得结果矩阵的线性值这个矩阵值将转换为XYZ,在我的例子中,我在2D屏幕上模拟3D://将矩阵转换为x,yvec4f_tv;multiplyMatrixAndVector(v,projectionCameraTransform,boxMatrix);floatx=(v[0]/v[3]+1.0f)*0.5f;floaty=(v[1]/v[3]+1.0f)*0.5f;CGPointMake(x*self.b

iphone - 这段代码中dispatch_after方法是并发执行的吗?

inttotal=0;//theseareglobals..BOOLdispatchCalled=NO;//-(void)callDispatch{dispatch_after(dispatch_time(DISPATCH_TIME_NOW,0.3*NSEC_PER_SEC),dispatch_get_current_queue(),^{dispatchCalled=YES;NSLog(@"Total,after300ms,is%i",total);});}-(void)play//thisismy"main"method..{NSLog(@"appstartsrunning");[s

iOS TableView 滞后问题,我正在使用分派(dispatch)和保存缓存

-(UITableViewCell*)tableView:(UITableView*)tableViewcellForRowAtIndexPath:(NSIndexPath*)indexPath{TableViewCell*cell=[tableViewdequeueReusableCellWithIdentifier:@"TableViewCell"forIndexPath:indexPath];cell.tag=indexPath.row;//cell.imageView.image=nil;//RoundedRectforcellimageCALayer*cellImageLay

ios - 为什么-tableView :heightForRowAtIndexPath: is a delegate method instead of a data source method?

这个问题在这里已经有了答案:DifferencebetweenUITableViewDelegateandUITableViewDatasource(4个答案)关闭6年前。我发现这个方法是一个UITableView委托(delegate)方法:-(CGFloat)tableView:(UITableView*)tableViewheightForRowAtIndexPath:(NSIndexPath*)indexPath{return20;}我真的很困惑,为什么它不是数据源方法?