UIView动画块更改会立即发生吗?

时间:2015-01-24 16:30:46

标签: objective-c uiview

我正在尝试动画UIImageView。我写了以下代码:

- (void)JumpAnimGoingDown {
NSLog(@"Started");
//Sets what happens in animation
self.character.frame = CGRectMake(self.view.frame.size.width / WidthDivision, (self.character.center.y - (self.view.frame.size.height / 18)) + self.view.frame.size.height, (self.view.frame.size.height * 4) / 45, self.view.frame.size.height / 9);



[UIView animateWithDuration:5.0f
                      delay:0
                    options:UIViewAnimationOptionCurveLinear

                 animations:^{

                     [self.view layoutIfNeeded];
                 }
                 completion:^(BOOL finished) {
                     // This block will execute when the animations finish

                     NSLog(@"Ended");

                     [self.view layoutIfNeeded];
                 }
 ];

}

但是当我在代码中调用此方法时,更改会立即发生: http://gyazo.com/b34fd7fa84ea25ace5cd656b4068e6aa 这也发生在我试图放入此动画块的任何其他代码中。老实说,我不知道为什么会这样,或者如何解决这个问题,所以非常感谢任何帮助!

对于那些想知道我试过改变

的人
 [UIView animateWithDuration:5.0f

[UIImageView animateWithDuration:5.0f

并且由于这没有任何区别,并且在之前的代码中我已经写过它已经如图所示工作然后我不认为这是一个问题。 感谢

1 个答案:

答案 0 :(得分:0)

您想要制作动画的任何更改都应在animations块内。

- (void)JumpAnimGoingDown
{
    NSLog(@"Started");

    [UIView animateWithDuration:5.0f
                          delay:0
                        options:UIViewAnimationOptionCurveLinear

                     animations:^{
                         //Sets what happens in animation
                         self.character.frame = CGRectMake(self.view.frame.size.width / WidthDivision, (self.character.center.y - (self.view.frame.size.height / 18)) + self.view.frame.size.height, (self.view.frame.size.height * 4) / 45, self.view.frame.size.height / 9);
                     }
                     completion:^(BOOL finished) {
                         // This block will execute when the animations finish

                         NSLog(@"Ended");

                         [self.view layoutIfNeeded];
                     }
     ];
}