SetBackgroundImage可防止动画正常运行

时间:2015-10-04 19:35:50

标签: ios swift uiview ios-animations

由于某些原因,当我更改按钮的背景时,我的动画无法正常运行。我是动画片的新手,正在尝试新的东西。我真的不需要改变背景,但它是我在草图中的方式,而且我认为它在更改时看起来更好。

代码:

@IBAction func didTapWithUsername(sender: AnyObject)
    {
        // When this button is tapped the two buttons below should move down far enough to reveal
        // two labels and two textboxes
        // choose animation
        if(userBtnTapped == 0)
        {
            tappedwithUserAnimationForSeperate()
            userBtnTapped = 1
            self.withUserNameBtn.setBackgroundImage(UIImage(named: "loginUserbtnWithFill.png"), forState: UIControlState.Normal)
        }
        else
        {
            tappedwithUserAnimationForClose()
            userBtnTapped = 0
            self.withUserNameBtn.setBackgroundImage(UIImage(named: "LoginWithUserbtn.png"), forState: UIControlState.Normal)
        }

    }

动画功能:

func tappedwithUserAnimationForSeperate()
{

    UIView.animateWithDuration(1.0, delay: 0, usingSpringWithDamping: 1.0, initialSpringVelocity: 5.0, options: [], animations: ({

        // code for animation goes here here
        self.withUserNameBtn.center.y = self.withUserNameBtn.center.y - 60
        self.withFBbtn.center.y = self.withFBbtn.center.y + 60
        self.signUpBtn.center.y = self.signUpBtn.center.y + 60



    }), completion: nil)
}

func tappedwithUserAnimationForClose()
{

    UIView.animateWithDuration(1.0, delay: 0, usingSpringWithDamping: 1.0, initialSpringVelocity: 5.0, options: [], animations: ({

        // code for animation goes here here
        self.withUserNameBtn.center.y = self.withUserNameBtn.center.y + 60
        self.withFBbtn.center.y = self.withFBbtn.center.y - 60
        self.signUpBtn.center.y = self.signUpBtn.center.y - 60


    }), completion: nil)
}

0 个答案:

没有答案