0

I'm relatively new to iOS development and I'm currently working on the signup/login screen for my app. I want one of the buttons to animate up once it's clicked, change its function and in this way, have a button 'get a new role' once it's clicked. The problem is that once I animate the button (via transfrom) upwards, it stops being clickable. Once I animate it back to its original position, it becomes clickable again.

It seems like as if the button is visible but not clickable...

(the button I'm talking about is: loginButton

Here's my code:

class FirstViewController: UIViewController {
    let loginButton: UIButton = {

        let button = UIButton(type: .system)
        button.setTitle("I already have an account ;)", for: .normal)
        button.backgroundColor = UIColor.rgb(red: 241, green: 245, blue: 249)
        button.layer.cornerRadius = 5
        button.titleLabel?.font = UIFont(name: "AvenirNext-Medium", size: 17)
        button.tintColor = UIColor.rgb(red: 123, green: 123, blue: 123)
        button.addTarget(self, action: #selector(handleLoginshow), for: .touchUpInside)
        button.isEnabled = true

        return button

    }()



    @objc func handleLoginshow() {

        // Animations triggered by LOGIN BUTTON
        UIView.animate(withDuration: 0.6, delay: 0, usingSpringWithDamping: 0.7, initialSpringVelocity: 0.4, options: .curveEaseOut, animations: {
            self.perspectiveImageContainerView.transform = CGAffineTransform(translationX: 0, y: -30)
            self.perspectiveImageContainerView.alpha = 0

            self.closeButton.alpha = 1
            self.closeButton.isEnabled = true

            self.signupButton.transform = CGAffineTransform(translationX: 0, y: -25)
            self.signupButton.alpha = 0

            self.introTextLabel.transform = CGAffineTransform(translationX: 0, y: -30)
            self.introTextLabel.alpha = 0

        })
        //


        // Animations triggered by LOGIN BUTTON
        UIView.animate(withDuration: 0.5, delay: 0.15, usingSpringWithDamping: 0.7, initialSpringVelocity: 0.4, options: .curveEaseOut, animations: {

            self.loginButton.transform = CGAffineTransform(translationX: 0, y: -70)
            self.loginButton.setTitle("Login", for: .normal)
            self.loginButton.setTitleColor(UIColor.rgb(red: 256, green: 256, blue: 256), for: .normal)
            self.loginButton.backgroundColor = UIColor.rgb(red: 18, green: 211, blue: 99)


            self.view.backgroundColor = UIColor.rgb(red: 241, green: 245, blue: 249)
            self.logoContainerView.backgroundColor = UIColor.rgb(red: 241, green: 245, blue: 249)

            self.emailTextField.alpha = 1
            self.emailTextField.transform = CGAffineTransform(translationX: 0, y: 0)
            self.passwordTextField.alpha = 1
            self.passwordTextField.transform = CGAffineTransform(translationX: 0, y: 0)

        })

        self.loginButton.addTarget(self, action: #selector(handleLogin), for: .touchUpInside)

    }

    @objc func handleLogin() {
        guard let email = emailTextField.text else { return }
        guard let password = passwordTextField.text else { return }

        Auth.auth().signIn(withEmail: email, password: password, completion: { (user, err) in

            if let err = err {
                print("Failed to sign in with email:", err)
                return
            }

            print("Successfully logged back in with user:", user?.uid ?? "")

            guard let mainTabBarController = UIApplication.shared.keyWindow?.rootViewController as? MainTabBarController else { return }
            mainTabBarController.setupViewControllers()
            self.dismiss(animated: true, completion: nil)

        })
    }

    fileprivate func setupInputFields() {
        let stackView = UIStackView(arrangedSubviews: [signupButton, loginButton])

        stackView.axis = .vertical
        stackView.spacing = 10
        stackView.distribution = .fillEqually

        view.addSubview(stackView)
        stackView.anchor(top: introTextLabel.bottomAnchor, left: view.leftAnchor, bottom: view.bottomAnchor, right: view.rightAnchor, paddingTop: 78, paddingLeft: 30, paddingBottom: 0, paddingRight: 30, width: 0, height: 110)

    }
}
Chanchal Chauhan
  • 1,530
  • 13
  • 25
CVE
  • 151
  • 2
  • 12
  • please edit to the code snippet causing the problem don't post all code – Shehata Gamal May 31 '18 at 11:26
  • @Sh_Khan, edited! – CVE May 31 '18 at 11:37
  • Are you sure a view isn't overlapping your login button after you do the animations? Maybe you have another view coming on top of it with 0 alpha, it wouldn't show for you but would stop the touch inputs. – Alan May 31 '18 at 12:57
  • @CvEijk - you need to provide code that will reproduce your issue. Try to narrow it down to the minimum needed - just the button you are animating, for example, including how you are adding it to the view. That way, someone else can copy/paste your code and run it to see what's happening. See: [How to create a Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) – DonMag May 31 '18 at 13:40

0 Answers0