首页 文章

UIButton文本动画不动画

提问于
浏览
0

在按钮的touchUpInside上,它运行一系列代码(所有数据相关,main函数中没有任何代码修改视图对象),代码所做的最后一件事就是调用我在下面粘贴的动画函数 . 问题是,动画看起来没什么应该的 .

Desired animation:

  • footerImg应淡出

  • footerBar文本应该淡入

  • footerBar文本应该淡出

  • footerImg应该淡入

文本和图像在屏幕上占据相同的位置,因此视觉应该是一个替换另一个,然后它回到原始状态 . 视图不是彼此嵌套的,它们共享同一个容器 .

Actual animation seen in simulator:

-footerImg永远不可见-footerBar文本在点击触发器后立即出现,没有动画-footerBar文本淡出-footerImg淡入

footerBar is a UIButton

  • 在动作开始之前,它处于启动状态,即按钮为空且清晰(用户不可见)

  • 如果重要,这不是触发该功能的按钮

  • 有一个清晰的背景,所以它的文本应该是唯一的动画进/出

footerImg is a UIImageView

  • 只是一个图标图像,没什么特别的
func animateFeedback() {
    UIView.animateWithDuration(0.25, delay: 0.0, usingSpringWithDamping: 1.0, initialSpringVelocity: 0, options: nil, animations: {
            self.footerImg.alpha = 0
            self.footerBar.alpha = 0

    },
        completion: { finished in
            self.footerBar.setTitle("Item added", forState: UIControlState.Normal)
        }
    )

    UIView.animateWithDuration(1.5, delay: 0.5, options: nil, animations: {
            self.footerBar.alpha = 1
        }
        , completion: nil
    )
    UIView.animateWithDuration(0.75, delay: 1.25, options: nil, animations: {
            self.footerBar.alpha = 0
        }
        , completion: { finished in
            self.footerBar.setTitle("", forState: UIControlState.Normal)
        }
    )
    UIView.animateWithDuration(0.25, delay: 1.5, options: nil, animations: {
            self.footerImg.alpha = 1
        }
        , completion: nil
    )
}

2 回答

  • 0

    对于序列动画,您应该在完成块中放置动画 . 例如 .

    footerBar文本应该淡入

    footerBar文本应该淡出

    试试这个:

    self.footerBar.alpha = 0;
    
            UIView.animateWithDuration(1.5, delay: 0.5, options: nil, animations: {
                self.footerBar.alpha = 1
            }
            , completion: { finished in
                UIView.animateWithDuration(0.75, delay: 1.25, options: nil, animations: {
                   self.footerBar.alpha = 0
                }
                , completion: { finished in
                   self.footerBar.setTitle("", forState: UIControlState.Normal)
                }
                )
           }
           )
    

    其他人也一样

  • 1

    评论您在“animateFeedback()”中拥有的所有代码,并将以下代码粘贴到其中

    UIView.animateWithDuration(1.5, delay: 0, options: nil, animations: { () -> Void in
            self.footerImg.alpha = 0;
            self.footerBar.setTitle("Item added", forState: UIControlState.Normal)
            },
            completion: { finished in
                UIView.animateWithDuration(1.5, delay: 0, options: nil, animations: { () -> Void in
                    self.footerImg.alpha = 1;
                    self.footerBar.setTitle("", forState: UIControlState.Normal)
                    },
                    completion: { finished in
                    }
                )
            }
        )
    

相关问题