我有一個問題,似乎只發生在設備上,而不是在模擬器中。iPhone NSTimer OpenGL問題
我的應用程序的動畫開始和使用這些方法停止:
NSTimer* animationTimer;
-(void)startAnimation
{
if(animationTimer == nil)
animationTimer = [NSTimer scheduledTimerWithTimeInterval:1.0f/60.0f target:self selector:@selector(drawView) userInfo:nil repeats:YES];
}
-(void)stopAnimation
{
[animationTimer invalidate];
animationTimer = nil;
}
在此工作正常,並開始drawView函數以60fps被稱爲仿真器。 在設備上(在iPod Touch上測試),scheduleTimerWithTimeInterval方法似乎不起作用。此外,[animationTimer invalidate]導致EXC_BAD_ACCESS。
我發現了一個顯而易見的小缺陷;如果(animationTimer!= nil)添加到stopAnimation方法將防止崩潰,但不能解決動畫計時器未正確初始化的問題。
編輯:以上不防止崩潰。 animationTimer!=零,但調用invalidate會導致EXC_BAD_ACCESS。
還應該加上,這個問題在設備上不會一直髮生。也許40%的時間。
你的代碼真的說:'if(animationTimer = nil)' – drawnonward 2010-05-07 08:59:20
不,更新。謝謝。 – Tobster 2010-05-07 16:14:09