OS4 改变了 iPhone 读取代码的方式吗?

发布于 2024-09-11 07:16:26 字数 3006 浏览 2 评论 0原文

我为 3.2 编写的代码在 OS4 中的表现有所不同。仍然没有错误,只是新的错误。

因此,我在名为“randomize”的 IBAction 中初始化 imageView,该 IBAction 会生成随机数,该随机数会进入 86 个案例之一,从而生成最终的动画和图像,0 和 86 之间代码的唯一区别是最终的 imageView.image (我只是不想将相同代码的 86 个副本放入其中,让您不得不费力地阅读)。无论哪种情况,动画 imageView.animationImages 都会运行。错误是,我第一次运行该操作时,imageView.animationImages 运行显示我的动画,然后不是完成代码并转到 imageView.image = [UIImage imageNamed:@"image36.png"],它现在只是显示无论我在 Interface Builder 中设置为实际的 imageView 背景。有时它会为一种情况运行动画,为另一种情况运行 imageview.image。有什么想法吗?

- (IBAction)randomize {
 int Number = arc4random() % 86;
 switch (Number) {
      case 0:
           imageView.animationImages = [NSArray arrayWithObjects:
                                               [UIImage imageNamed:@"image1.png"],
                                               [UIImage imageNamed:@"image2.png"],
                                               [UIImage imageNamed:@"image3.png"],
                                               [UIImage imageNamed:@"image4.png"],
                                               [UIImage imageNamed:@"image5.png"],
                                               [UIImage imageNamed:@"image6.png"],
                                               [UIImage imageNamed:@"image7.png"],
                                               [UIImage imageNamed:@"image8.png"],
                                               [UIImage imageNamed:@"image9.png"],
                                               [UIImage imageNamed:@"image10.png"],
                                       [UIImage imageNamed:@"image0.png"],nil];
           imageView.animationDuration = 0.50;
           [imageView setAnimationRepeatCount: 1];
           [imageView startAnimating]; 
           imageView.image = [UIImage imageNamed:@"image36.png"];

           break;
      case 1:
           imageView.animationImages = [NSArray arrayWithObjects:
                                               [UIImage imageNamed:@"image1.png"],
                                               [UIImage imageNamed:@"image2.png"],
                                               [UIImage imageNamed:@"image3.png"],
                                               [UIImage imageNamed:@"image4.png"],
                                               [UIImage imageNamed:@"image5.png"],
                                               [UIImage imageNamed:@"image6.png"],
                                               [UIImage imageNamed:@"image7.png"],
                                               [UIImage imageNamed:@"image8.png"],
                                               [UIImage imageNamed:@"image9.png"],
                                               [UIImage imageNamed:@"image10.png"],
                                       [UIImage imageNamed:@"image0.png"],nil];
           imageView.animationDuration = 0.50;
           [imageView setAnimationRepeatCount: 1];
           [imageView startAnimating]; 
           imageView.image = [UIImage imageNamed:@"image37.png"];

           break;

The code I wrote for 3.2 performs differently in OS4. Still no errors, just new bugs.

So I'm initializing the imageView inside an IBAction called "randomize" that produces and random number that goes to one of 86 cases producing a resulting animation and image, the only difference in code between 0 and 86 is that final imageView.image (I just didn't want to past 86 copies of the same code in for you to have to wade through ). No matter what the case, the animation imageView.animationImages runs. The bug is that the first time I run the action, imageView.animationImages runs showing my animation, then instead of completing the code and going to the imageView.image = [UIImage imageNamed:@"image36.png"], it now just shows whatever I have set as the actual imageView background in Interface Builder. And Sometimes it runs the animation for one case and the imageview.image for another. Any ideas?

- (IBAction)randomize {
 int Number = arc4random() % 86;
 switch (Number) {
      case 0:
           imageView.animationImages = [NSArray arrayWithObjects:
                                               [UIImage imageNamed:@"image1.png"],
                                               [UIImage imageNamed:@"image2.png"],
                                               [UIImage imageNamed:@"image3.png"],
                                               [UIImage imageNamed:@"image4.png"],
                                               [UIImage imageNamed:@"image5.png"],
                                               [UIImage imageNamed:@"image6.png"],
                                               [UIImage imageNamed:@"image7.png"],
                                               [UIImage imageNamed:@"image8.png"],
                                               [UIImage imageNamed:@"image9.png"],
                                               [UIImage imageNamed:@"image10.png"],
                                       [UIImage imageNamed:@"image0.png"],nil];
           imageView.animationDuration = 0.50;
           [imageView setAnimationRepeatCount: 1];
           [imageView startAnimating]; 
           imageView.image = [UIImage imageNamed:@"image36.png"];

           break;
      case 1:
           imageView.animationImages = [NSArray arrayWithObjects:
                                               [UIImage imageNamed:@"image1.png"],
                                               [UIImage imageNamed:@"image2.png"],
                                               [UIImage imageNamed:@"image3.png"],
                                               [UIImage imageNamed:@"image4.png"],
                                               [UIImage imageNamed:@"image5.png"],
                                               [UIImage imageNamed:@"image6.png"],
                                               [UIImage imageNamed:@"image7.png"],
                                               [UIImage imageNamed:@"image8.png"],
                                               [UIImage imageNamed:@"image9.png"],
                                               [UIImage imageNamed:@"image10.png"],
                                       [UIImage imageNamed:@"image0.png"],nil];
           imageView.animationDuration = 0.50;
           [imageView setAnimationRepeatCount: 1];
           [imageView startAnimating]; 
           imageView.image = [UIImage imageNamed:@"image37.png"];

           break;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一人独醉 2024-09-18 07:16:26

如果我不得不猜测的话,您在 86 个案例中随机丢失了中断语句。请考虑重构一个方法......

If I had to guess, you're missing break statments at random intervals in your 86 cases. Please consider refactoring to a method...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文