Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
845 views
in Technique[技术] by (71.8m points)

view - Button is not reacting after placing him on a StackView / Swift / iOS

I changed the layout on my HomeViewController and now there are some problems: At the beginning I placed the Button on the normal view and he worked perfectly but now I created a big mapView and placed a small StackView on it which contains the Button, which is not functioning but why? This is the Code:

func configureMapView() {
        view.addSubview(mapView)
//        mapView.sizeToFit()
        
        //Constraints
        mapView.translatesAutoresizingMaskIntoConstraints = false
        mapView.heightAnchor.constraint(equalTo: view.heightAnchor).isActive = true
        mapView.widthAnchor.constraint(equalTo: view.widthAnchor).isActive = true
    }
    
    
    
    func ConfigureChangeMapViewButton() {
        changeMapTypeButton.setImage(mapImage, for: .normal)
        changeMapTypeButton.layer.cornerRadius = 25
        changeMapTypeButton.backgroundColor = .clear
        changeMapTypeButton.addTarget(self, action: #selector(changeMapType), for: .touchUpInside)
        
        //Constraints
        changeMapTypeButton.translatesAutoresizingMaskIntoConstraints = false
        changeMapTypeButton.widthAnchor.constraint(equalToConstant: 25).isActive = true
        changeMapTypeButton.heightAnchor.constraint(equalToConstant: 1).isActive = true
    }
    
    func ConfigureMapLegend() {
        mapView.addSubview(mapLegend)
        mapLegend.backgroundColor = .systemPurple
        mapLegend.layer.cornerRadius = 15
        mapLegend.alignment = .center
        mapLegend.axis = .vertical
        mapLegend.distribution = .fillEqually
        mapLegend.spacing = 7
        
        //Elements
        mapLegend.addArrangedSubview(changeMapTypeButton)
        mapLegend.addArrangedSubview(child1)
        mapLegend.addArrangedSubview(child2)
        
        //Constraints
        mapLegend.translatesAutoresizingMaskIntoConstraints = false
        mapLegend.widthAnchor.constraint(equalToConstant: 40).isActive = true
        mapLegend.heightAnchor.constraint(equalToConstant: 160).isActive = true
        mapLegend.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -15).isActive = true
        mapLegend.topAnchor.constraint(equalTo: view.topAnchor, constant: 50).isActive = true
    }

This is how the finished View looks like:

enter image description here

question from:https://stackoverflow.com/questions/65914600/button-is-not-reacting-after-placing-him-on-a-stackview-swift-ios

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...