0

我需要一个一个地完成一系列步骤。总之,我有三个步骤要完成,它们都在一个 while 循环中。一旦完成了三个测试,那么只有在那时,用户才应该退出 while 循环。问题是这些步骤需要按顺序完成,并且要求用户按顺序进行每个测试,如果通过,则继续进行下一步。

以下是相关代码:

int passCount = 0;
    BOOL flatPass = FALSE;
    BOOL landscapePass = FALSE;
    BOOL portraitPass = FALSE;

while (passCount < 3) {


        if (flatPass == FALSE) {

            if (device.orientation == UIDeviceOrientationFaceUp || device.orientation == UIDeviceOrientationFaceDown) {

                [self pushSound];

            }

        }


        else if (landscapePass == FALSE) {

            if (device.orientation == UIDeviceOrientationLandscapeLeft || device.orientation == UIDeviceOrientationLandscapeRight) {

                [self pushSound];

            }

        }


        else if (portraitPass == FALSE) {

            if (device.orientation == UIDeviceOrientationPortrait || device.orientation == UIDeviceOrientationPortraitUpsideDown) {

                [self pushSound];

            }

        }

    }

我需要用户将 iOS 设备定位在每个位置,并播放哔声表示测试成功。一旦按顺序完成所有三个测试,我希望用户退出循环。我认为每次清除测试时,我都会将 passCount 计数器增加 1,直到达到 3,这将使我退出循环。不过,我的问题是如何按顺序进行每个测试。

4

2 回答 2

0

假设这没有在主 UI 线程上运行,删除while循环,用条件替换每个和,if当测试通过时将适当的布尔标志设置为 true,然后你就完成了。else ifwhile

于 2012-12-05T20:36:26.143 回答
0

你可以在

deviceDidRotate()

您需要一个对象变量来保存当前进度,或者像您所做的那样使用枚举:

int step; 

然后在 deviceDidRotate 你检查:

   if (step == 0 && device.orientation == UIDeviceOrientationFaceUp ) {
     step = 1;
   } else if (step == 1 && device.orientation == UIDeviceOrientationLandscapeLeft) {
     step = 2;
   } else if (step == 2 && device.orientation == UIDeviceOrientationPortrait ) {
     // successful!
     // now do action, reset step? call method 
   }
于 2012-12-05T20:47:42.690 回答