XCode 5和XCode 6的动画变化



我最近刚升级到xcode 6,突然我的一堆代码在我的应用程序不工作。最初的情况是,如果你触碰屏幕的左边,你的角色就会面向左边,如果你触碰右边,他就会面向右边。当某种交互发生时,会有一种方法检查他是向左看还是向右看,动画也会相应出现。现在在XCode 6中,他可以看向左边,但播放与右边相关的动画,当我再次点击左键时,他会看向左边,然后只播放右边的动画。我有一个我认为发生故障的代码部分的示例,但我似乎无法排除原因。

if (Stickman.image == [UIImage imageNamed:@"BjLeft6.png"])
    {
    Stickman.animationImages = [NSArray arrayWithObjects:
                            [UIImage imageNamed:@"BjLeft2.png"],
                            [UIImage imageNamed:@"BjLeft2.png"],
                            [UIImage imageNamed:@"BjLeft3.png"],
                            [UIImage imageNamed:@"BjLeft4.png"],
                            [UIImage imageNamed:@"BjLeft4.png"],
                            [UIImage imageNamed:@"BjLeft4.png"],
                            [UIImage imageNamed:@"BjLeft5.png"],
                            [UIImage imageNamed:@"BjLeft6.png"],
                            [UIImage imageNamed:@"BjLeft5.png"],
                            [UIImage imageNamed:@"BjLeft4.png"],
                            [UIImage imageNamed:@"BjLeft3.png"],
                            [UIImage imageNamed:@"BjLeft2.png"],
                            [UIImage imageNamed:@"BjLeft1.png"], nil];
    [Stickman setAnimationRepeatCount:1];
    Stickman.animationDuration = .5;
    [Stickman startAnimating];

    }
    else
    {
    Stickman.image = [UIImage imageNamed:@"BjRight6.png"];
    Stickman.animationImages = [NSArray arrayWithObjects:
                                [UIImage imageNamed:@"BjRight2.png"],
                                [UIImage imageNamed:@"BjRight2.png"],
                                [UIImage imageNamed:@"BjRight3.png"],
                                [UIImage imageNamed:@"BjRight4.png"],
                                [UIImage imageNamed:@"BjRight4.png"],
                                [UIImage imageNamed:@"BjRight4.png"],
                                [UIImage imageNamed:@"BjRight5.png"],
                                [UIImage imageNamed:@"BjRight6.png"],
                                [UIImage imageNamed:@"BjRight5.png"],
                                [UIImage imageNamed:@"BjRight4.png"],
                                [UIImage imageNamed:@"BjRight3.png"],
                                [UIImage imageNamed:@"BjRight2.png"],
                                [UIImage imageNamed:@"BjRight1.png"],       nil];
    [Stickman setAnimationRepeatCount:1];
    Stickman.animationDuration = .5;
    [Stickman startAnimating];
     }

比较不好:

(Stickman.image == [UIImage imageNamed:@"BjLeft6.png"])

这是比较地址,UIImage imageNamed可能不会返回与Stickman.image接收到的相同的图像实例,==将失败。

当比较是否相等时,比较实例地址很少是正确的解决方案。

相关内容

  • 没有找到相关文章

最新更新