ios - UIButton 不使用 UIViewAnimationOptionTransitionFlipFromTop 设置动画

标签 ios objective-c uiviewanimation

我尝试使用 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) {

        }];
    }];
}];

请让我知道这里需要修复什么。以下是动画:

enter image description here

最佳答案

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/

相关文章:

android - 使用 Apple( map )URL Scheme 时,非 iOS 设备会发生什么情况?

ios - int plus plus 和 int plus equals 之间的差值等于 1

ios - 在 iOS7 上看不到动态 subview (在 iOS6 上工作)

iphone - ELCImagePickerController 的 Indicatorview

ios - Swift,使用函数 UIView.removeFromSuperview 作为 forEach 函数中 View 数组的参数

ios - 在后台 ios 应用程序中播放音乐

objective-c - 当你运行 self=[super init] 并且它返回 nil 时,正确的 react 是什么?

ios - 在 ios 中的动画期间,对 imageview 的手势不起作用

ios - UIView 动画 layoutIfneeded 不工作

ios - 如何在 Swift 中加载 GIF 图像?