'if'语句中的动画不起作用

时间:2015-06-02 12:54:22

标签: ios animation if-statement

这是我的问题:

我有一些动画块,它们都被执行得很好。但我也希望执行一些动画,只有在特定BOOL值为真时才会执行。

BOOL正确地取TRUE值,代码进入if语句,因为我的日志评论正在打印。似乎只显示动画。我尝试过不同的CGPoint值但仍然相同。 也许我错过了关于动画的东西。

我没有经常使用它们。 任何帮助都会很棒!

以下是代码示例:

// line 4 - second particle
UIImageView* particle8 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"particle"]];
particle8.frame = CGRectMake(p8.x, p8.y, particleWidth, particleWidth);
[self addSubview:particle8];
[UIView animateWithDuration:2
                      delay:0
                    options:UIViewAnimationOptionAllowUserInteraction|UIViewAnimationOptionRepeat
                 animations:^{
                     particle8.frame = CGRectMake(p7.x, p7.y, particleWidth, particleWidth); }
                 completion:^(BOOL finished){[particle8 removeFromSuperview]; }];


if (_isSmartGridOn) {
    // line 2b - first particle
    UIImageView* particle9 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"particle"]];
    particle9.frame = CGRectMake(ep.x - 5, ep.y - 5, particleWidth, particleWidth);
    [self addSubview:particle9];
    [UIView animateWithDuration:1
                          delay:0
                        options:UIViewAnimationOptionAllowUserInteraction|UIViewAnimationOptionRepeat
                     animations:^{
                         particle9.frame = CGRectMake(p10.x, p10.y, particleWidth, particleWidth); }
                     completion:^(BOOL finished){[particle9 removeFromSuperview]; }];
}

1 个答案:

答案 0 :(得分:0)

您只有错字或复制/粘贴错误:

particle8.frame = CGRectMake(p10.x, p10.y, particleWidth, particleWidth);
        ^ should be 9         ^^     ^^ looks like these might be wrong too