Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

855
Views
UIStackView: oculta y contrae la subvista con animación

Estoy tratando de ocultar la subvista de UIStackView de esta manera:

 UIViewPropertyAnimator.runningPropertyAnimator(withDuration: 2.0, delay: 0, options: [.curveEaseOut], animations: { self.label.isHidden = true self.label.alpha = 0.0 self.stackView.layoutIfNeeded() })

Sin embargo, la etiqueta desaparece instantáneamente con el uso de este código. Sospecho que esto se debe a la configuración de isHidden en verdadero, que se requiere para colapsar.

¿Hay alguna forma de ocultar y colapsar la vista secundaria de UIStackView con animación? ¿O podría ser mejor no usar UIStackView en absoluto?

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Según la documentación de Apple :

Puede animar tanto los cambios en la propiedad isHidden de la subvista organizada como los cambios en las propiedades de la vista de pila colocando estos cambios dentro de un bloque de animación.

He probado el siguiente código con el simulador de iOS 12.1 y funciona como se esperaba.

 UIView.animate( withDuration: 2.0, delay: 0.0, options: [.curveEaseOut], animations: { self.label.isHidden = true self.label.alpha = 0.0 })

Gif de animación de subvista arreglada

over 4 years ago · Santiago Trujillo Report

0

Puede animar propiedades de vista como alpha , color , etc. Sin embargo, algunas cosas suceden instantáneamente, en este caso isHidden .

Aquí hay un ejemplo usando UIView.animate :

 UIView.animate(withDuration: 2, delay: 0, options: .curveEaseOut, animations: { self.label.alpha = 0 // Changes the label's layer alpha value }, completion: { finished in self.label.isHidden = true // Hides the label self.label.layer.alpha = 1 // Resets the label's alpha without un-hiding it })

Usando UIViewPropertyAnimator :

 UIViewPropertyAnimator.runningPropertyAnimator(withDuration: 2, delay: 0, options: .curveEaseOut, animations: { self.label.alpha = 0 // Sets the label's alpha }) { _ in self.label.isHidden = true // Hides the label self.label.alpha = 1 // Resets the label's alpha without un-hiding it }
over 4 years ago · Santiago Trujillo Report

0

He probado tu código. esta animando

 if self.stackView.subviews.count > 0 { UIViewPropertyAnimator.runningPropertyAnimator(withDuration: 1.0, delay: 0, options: [.curveEaseOut], animations: { self.stackView.subviews[0].isHidden = true self.stackView.subviews[0].alpha = 0.0 self.stackView.layoutIfNeeded() }) { (position) in self.stackView.subviews[0].removeFromSuperview() } }

pantalla inicial

animado

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!