Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/93.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios swift:修复按钮动画_Ios_Swift - Fatal编程技术网

Ios swift:修复按钮动画

Ios swift:修复按钮动画,ios,swift,Ios,Swift,当我的应用程序统计时,我想显示按钮动画。在故事板中,我的按钮有height=50和y=-50。我在代码中有这个动作 @IBOutlet weak var imageView: UIImageView! override func viewDidLoad() { super.viewDidLoad() buttonAnimation() } func buttonAnimation() { self.buttonTopConstraint.constant += se

当我的应用程序统计时,我想显示按钮动画。在故事板中,我的按钮有
height=50
y=-50
。我在代码中有这个动作

@IBOutlet weak var imageView: UIImageView!
override func viewDidLoad() 
{
    super.viewDidLoad()
    buttonAnimation()
}

func buttonAnimation() 
{
    self.buttonTopConstraint.constant += self.ButtonHeightConstraint.constant
    UIView.animate(withDuration: 1.5, delay: 0.0, options: [], animations: 
        {
            self.view.layoutIfNeeded()
        }
    )
}

动画效果很好。但当应用程序在故事板中启动我的背景图像视图时,不同的图像视图也被设置为动画。但我只需要按钮的动画。如何修复它?

使用
CGAffineTransform
设置按钮的动画<代码>从情节提要中删除y=-50,并将其保留在所需位置。然后在
视图将出现
视图显示
中调用此函数:

func animateButton() {
    yourButton.transform = CGAffineTransform(translationX: yourButton.frame.origin.x, y: yourButton.frame.origin.y - 50)
    UIView.animate(withDuration: 1.5, delay: 0.0, options: [], animations: {
        self.yourButton.transform = .identity
    }, completion: nil)
}

使用
CGAffineTransform
设置按钮的动画<代码>从情节提要中删除y=-50,并将其保留在所需位置。然后在
视图将出现
视图显示
中调用此函数:

func animateButton() {
    yourButton.transform = CGAffineTransform(translationX: yourButton.frame.origin.x, y: yourButton.frame.origin.y - 50)
    UIView.animate(withDuration: 1.5, delay: 0.0, options: [], animations: {
        self.yourButton.transform = .identity
    }, completion: nil)
}

不要在
viewDidLoad
中调用动画,因为此时将设置控制器的所有视图

使用
viewdide
调用动画方法

  override func viewDidAppear() 
   {
    buttonAnimation()
   }

不要在
viewDidLoad
中调用动画,因为此时将设置控制器的所有视图

使用
viewdide
调用动画方法

  override func viewDidAppear() 
   {
    buttonAnimation()
   }