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

320
Views
¿Cómo puedo verificar si existe un controlador de vista infantil?

Estoy implementando una diapositiva en el menú de estilo.

El menú se agrega como un controlador de vista secundario en el programa y luego se anima a la vista. Luego lo elimino de la vista una vez que se ha cerrado.

Me gustaría presentar un UIPanGestureRecognizer para que el usuario pueda pasarlo a la vista, sin embargo, la lógica para agregar la vista solo se activa al presionar abrir.

Me gustaría evitar agregarlo muchas veces y en cada gesto, así que estaba pensando en verificar si estaba presente, si no, agregarlo, luego animarlo.

lazy var menuController = MenuController()

 private var menuWidth: CGFloat = 300 private let keyWindow = UIApplication.shared.keyWindow override func viewDidLoad() { super.viewDidLoad() setupNavigationItems() setupTableView() menuController.view.frame = CGRect(x: -menuWidth, y: 0, width: menuWidth, height: view.frame.height) let panGesture = UIPanGestureRecognizer(target: self, action: #selector(handlePan)) view.addGestureRecognizer(panGesture) } @objc func handlePan(gesture: UIPanGestureRecognizer) { let translation = gesture.translation(in: view) let transform = CGAffineTransform(translationX: translation.x, y: 0) menuController.view.transform = transform navigationController?.view.transform = transform } @objc func handleOpen() { keyWindow?.addSubview(menuController.view) animateMenuController(transform: CGAffineTransform(translationX: self.menuWidth, y: 0)) { } addChild(menuController) } @objc func handleHide() { animateMenuController(transform: .identity) { [weak self] in self?.menuController.view.removeFromSuperview() self?.menuController.removeFromParent() } }

esperaba hacer algo asi

 @objc func handlePan(gesture: UIPanGestureRecognizer) { if view.subviews.contains(MenuController) { print("yes") } let translation = gesture.translation(in: view) let transform = CGAffineTransform(translationX: translation.x, y: 0) menuController.view.transform = transform navigationController?.view.transform = transform }

Pero esto no es correcto.

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Puedes intentar usar la propiedad childrens de vc

 if !children.isEmpty { // this assumes 1 vc tell if you have more print("YES") }

o

 if let _ = children.first(where:{ $0 is menuController}) { // this assumes 1 vc tell if you have more print("YES") }

es posible que también deba agregarlo a

 view.addSubview(menuController.view)

no a keyWindow

over 4 years ago · Santiago Trujillo Report

0

Puede verificar classForCoder con el nombre de su clase

 if children.first(where: { String(describing: $0.classForCoder) == "MenuController" }) != nil { print("we have one") }

Sin embargo, esto introduce una "cadena mágica", ya que simplemente cambiar el nombre de su clase rompería esta lógica.

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!