在 iPhone 上渲染 Watch 帧而不停止的最佳方法

best way to render Watch frames on iPhone without grinding to a halt

我正在尝试通过渲染 UIImage 'frames' 来扩展 Apple Watch 的功能,然后每 500 毫秒(每秒 2 帧)在我的 WKInterfaceImage 上设置它们。

我的计划是尝试渲染不需要高细节或帧率的 8 位风格游戏,然后在手表应用程序上获得箭头按钮以指示游戏状态如何变化。

所以我有一个游戏 class,它有一个 'tick' 方法,其中 returns 一个 UIImage。每次调用 'tick' 都会让游戏前进一分。想想俄罗斯方块,游戏中的每个 'tick' 都会将下落的方块向下移动一个方块 space。游戏进行 'ticks' 直到有来自用户的交互。在调用旋转块时,我告诉游戏 class 在下一个 'tick' 发生时向左或向右旋转。以下是我的 WKInterfaceController class 的相关部分。

- (void)willActivate
{
    // This method is called when watch view controller is about to be visible to user
    NSLog(@"%@ will activate", self);

    // wait 2 seconds until game 'starts'
    [self performSelector:@selector(timerFired) withObject:nil afterDelay:2.];
}

- (void)timerFired
{
    dispatch_async(dispatch_get_main_queue(), ^{
        [self.theImage setImage:[self.game tick]];

        [self performSelector:@selector(timerFired) withObject:nil afterDelay:.5];
    });
}

- (IBAction)leftButtonPressed
{
    self.game.futureMove = FutureMoveAntiClockWise;
}
- (IBAction)rightButtonPressed
{
    self.game.futureMove = FutureMoveClockWise;
}

现在,令人惊讶的是,所有代码都运行良好 - 持续了几秒钟。然后一切都变得越来越慢,越来越落后(就帧而言)。大约 10 秒后,按下向左或向右旋转按钮只会在几秒后显示在呈现的 UIImage 上。

手表应用程序开始以每秒 30 帧的速度渲染(如果我想要的话),然后爬行速度越来越慢,最终停止。有没有更好的方法可以在 WKInterfaceImage 上反复可靠地 setImage 而不会减慢速度?

我太接近了!!

感谢您的评论。更新到 Xcode 6.3 后,它工作正常并且不会滞后,但我会注意@MikeSwanson 并希望 Apple 拒绝我的应用程序:(。