OS4 改变了 iPhone 读取代码的方式吗?
我为 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我不得不猜测的话,您在 86 个案例中随机丢失了中断语句。请考虑重构一个方法......
If I had to guess, you're missing break statments at random intervals in your 86 cases. Please consider refactoring to a method...