我尝试使用 UIViewAnimationOptionTransitionFlipFromTop
尝试实现以下动画,但它不起作用并且会立即更改图像。以下是我使用的代码:
[self.thanksButton setImage:[UIImage imageNamed:@"frame1_image"] forState:UIControlStateNormal];
[UIView animateWithDuration:3.0 delay:0 options:UIViewAnimationOptionTransitionFlipFromTop animations:^{
} completion:^(BOOL finished) {
[self.thanksButton setImage:[UIImage imageNamed:@"frame4_image"] forState:UIControlStateNormal];
}];
还尝试将图像分成四个不同的帧,并使用像这样的嵌套动画将这些图像一张一张地应用,
[UIView animateWithDuration:3.0 animations:^{
[self.thanksButton setImage:[UIImage imageNamed:@"frame2_image"] forState:UIControlStateNormal];
} completion:^(BOOL finished) {
[UIView animateWithDuration:3.0 animations:^{
[self.thanksButton setImage:[UIImage imageNamed:@"frame3_image"] forState:UIControlStateNormal];
} completion:^(BOOL finished) {
[UIView animateWithDuration:3.0 animations:^{
[self.thanksButton setImage:[UIImage imageNamed:@"frame4_image"] forState:UIControlStateNormal];
} completion:^(BOOL finished) {
}];
}];
}];
请让我知道这里需要修复什么。以下是动画:
最佳答案
setImage 不能被动画化,只是通过将 UIView animationblock 放入其中,因此 completionBlock 不会等待 3 秒,而是立即调用。要查看实际效果,请在 self.thanksbutton 上设置一些 alpha,例如 0.3、0.5、1(我认为它看起来不太好,但您应该会看到效果)
此外,我会制作 2 个按钮,这样我就可以使用:
[UIView transitionFromView:firstButton
toView:theOtherButton duration:0.3f
options:UIViewAnimationOptionTransitionFlipFromBottom
completion:^(BOOL finished) {
}];
关于ios - UIButton 不使用 UIViewAnimationOptionTransitionFlipFromTop 设置动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21287757/