ios – Cannot faucet buttons in UIStackView

0
3


I do know there are loads of questions like this, however I believe I attempted just about all the pieces and it didn’t work. I’m attempting so as to add 2 buttons to a stackView however after I do this – I am unable to faucet them anymore…

enter image description here

Right here is my code:

       personal func addConstraintsForItems() {
        let imageViewXAnchorConstraint = imageView.centerXAnchor.constraint(equalTo: view.centerXAnchor)
        let imageViewYAnchorConstraint = imageView.centerYAnchor.constraint(equalTo: view.centerYAnchor)
        imageViewWidthConstraint = imageView.widthAnchor.constraint(equalToConstant: 120)
        imageViewHeightConstraint = imageView.heightAnchor.constraint(equalToConstant: 320)

        NSLayoutConstraint.activate([imageViewWidthConstraint, imageViewHeightConstraint, imageViewXAnchorConstraint, imageViewYAnchorConstraint])

        let borderViewTopConstraint = borderView.topAnchor.constraint(equalTo: imageView.topAnchor)
        let borderViewLeftConstraint = borderView.leadingAnchor.constraint(equalTo: imageView.leadingAnchor)
        let borderViewRightConstraint = borderView.trailingAnchor.constraint(equalTo: imageView.trailingAnchor)
        let borderViewBottomConstraint = borderView.bottomAnchor.constraint(equalTo: imageView.bottomAnchor)

        NSLayoutConstraint.activate([borderViewTopConstraint, borderViewLeftConstraint, borderViewRightConstraint, borderViewBottomConstraint])

        let buttonStackView = UIStackView()
        buttonStackView.addArrangedSubview(rotateButton)
        buttonStackView.addArrangedSubview(deleteButton)
        buttonStackView.axis = .vertical
        buttonStackView.spacing = 20
        buttonStackView.distribution = .fillEqually
        imageView.addSubview(buttonStackView)

        rotateButton.isUserInteractionEnabled = true
        deleteButton.isUserInteractionEnabled = true

        buttonStackView.translatesAutoresizingMaskIntoConstraints = false
        let trailingStackViewConstraint = buttonStackView.trailingAnchor.constraint(equalTo: imageView.trailingAnchor, fixed: 40)
        let centerYStackViewConstraint = buttonStackView.centerYAnchor.constraint(equalTo: imageView.centerYAnchor)
        let stackViewWidthConstraint = buttonStackView.widthAnchor.constraint(equalToConstant: 50)
        let stackViewHeightConstraint = buttonStackView.heightAnchor.constraint(equalToConstant: 100)

        NSLayoutConstraint.activate([trailingStackViewConstraint, centerYStackViewConstraint, stackViewWidthConstraint, stackViewHeightConstraint])
    }

Button creation code:

    personal let rotateButton: UIButton = {
        let button = UIButton()
        button.translatesAutoresizingMaskIntoConstraints = false
        let newSize = CGSize(width: 25, top: 25)
        let picture = UIImage(systemName: "rotate.left")
        let resizedImage = picture?.withConfiguration(UIImage.SymbolConfiguration(pointSize: newSize.width, weight: .medium))
        button.setImage(resizedImage, for: .regular)
        button.tintColor = .systemPink
        button.isHidden = true
        return button
    }()

    personal let deleteButton: UIButton = {
        let button = UIButton()
        button.translatesAutoresizingMaskIntoConstraints = false
        let newSize = CGSize(width: 25, top: 25)
        let picture = UIImage(systemName: "trash")
        let resizedImage = picture?.withConfiguration(UIImage.SymbolConfiguration(pointSize: newSize.width, weight: .medium))
        button.setImage(resizedImage, for: .regular)
        button.tintColor = .systemPink
        button.isHidden = true
        return button
    }()

They’re hidden by default however I toggle it off as soon as I press on the picture.
Additionally, I attempted to set the imageView.subview(stackview) on this perform:

 personal func setupView() {
        view.addSubview(imageView)
        imageView.addSubview(borderView)
    }

But it surely all the time crashes.
My viewDidLoad():

override func viewDidLoad() {
        tremendous.viewDidLoad()
        view.backgroundColor = .white

        setupView()
        addConstraintsForItems()
        createCircles()

        addTapGestureRecognizer()
        addPinchGestureRecognizer()
        addRotationGesture()
        addDeletePhotoButton()
    }

LEAVE A REPLY

Please enter your comment!
Please enter your name here