我正在尝试动画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
并且由于这没有任何区别,并且在之前的代码中我已经写过它已经如图所示工作然后我不认为这是一个问题。 感谢
答案 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];
}
];
}