ボタンの背景を変更すると、何らかの理由でアニメーションが正しく実行されません。私はアニメーションが初めてで、何か新しいことを試みていました。背景を変更する必要はあまりありませんが、それは私がスケッチで持っていた方法であり、私の意見では、変更すると見栄えが良くなります。
コード:
@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)
}