UIView 动画块更改立即发生?

UIView Animation block changes take place instantly?

我正在尝试为 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

因为这没有任何区别,而且在我之前编写的代码中,它的工作原理如图所示,所以我认为这不是问题。 谢谢

您想要动画化的任何更改都应该在 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];
                     }
     ];
}